-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (108 loc) · 4.28 KB
/
release.yml
File metadata and controls
115 lines (108 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Release Package
on:
push:
branches: [main]
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version-changed: ${{ steps.check.outputs.changed }}
current-version: ${{ steps.check.outputs.current-version }}
previous-version: ${{ steps.check.outputs.previous-version }}
is-prerelease: ${{ steps.check.outputs.is-prerelease }}
npm-tag: ${{ steps.check.outputs.npm-tag }}
steps:
- uses: actions/checkout@v4
- name: Check if version needs publishing
id: check
run: |
current_version=$(jq -r '.version' package.json)
package_name=$(jq -r '.name' package.json)
echo "current-version=$current_version" >> $GITHUB_OUTPUT
# Check if this version exists on npm
if npm view "${package_name}@${current_version}" version 2>/dev/null; then
echo "Version $current_version already published to npm"
echo "changed=false" >> $GITHUB_OUTPUT
previous_version="$current_version"
else
echo "Version $current_version not found on npm, will publish"
echo "changed=true" >> $GITHUB_OUTPUT
# Get the latest published version for reference
previous_version=$(npm view "${package_name}" version 2>/dev/null || echo "none")
fi
echo "previous-version=$previous_version" >> $GITHUB_OUTPUT
# Check if this is a pre-release version
if [[ "$current_version" =~ -(alpha|beta|rc|dev|pre|canary|next) ]]; then
echo "is-prerelease=true" >> $GITHUB_OUTPUT
tag="$(echo "$current_version" | cut -d'-' -f2)"
echo "npm-tag=$tag" >> $GITHUB_OUTPUT
echo "Detected pre-release version with tag: $tag"
else
echo "is-prerelease=false" >> $GITHUB_OUTPUT
echo "npm-tag=latest" >> $GITHUB_OUTPUT
echo "Detected stable release version"
fi
build-and-publish:
runs-on: ubuntu-latest
needs: check-version
if: needs.check-version.outputs.version-changed == 'true'
permissions:
contents: read
id-token: write
outputs:
published-version: ${{ needs.check-version.outputs.current-version }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
registry-url: 'https://registry.npmjs.org'
- name: enable corepack
run: |
corepack enable
corepack prepare yarn@4.11.0 --activate
- name: cache yarn dependencies
uses: actions/cache@v4
with:
path: ~/.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashfiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --immutable
- run: yarn build
- name: Publish to npm
run: |
# Yarn 4.11.0 with OIDC trusted publishing
if [ "${{ needs.check-version.outputs.is-prerelease }}" == "true" ]; then
yarn npm publish --access public --tag ${{ needs.check-version.outputs.npm-tag }}
else
yarn npm publish --access public
fi
create-release:
runs-on: ubuntu-latest
needs: [check-version, build-and-publish]
if: needs.build-and-publish.result == 'success' && needs.check-version.outputs.is-prerelease ==
'false'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: enable corepack
run: |
corepack enable
corepack prepare yarn@4.9.2 --activate
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check-version.outputs.current-version }}
release_name: v${{ needs.check-version.outputs.current-version }}
body: |
See [CHANGELOG](https://github.com/ReforgeHQ/cli/blob/main/CHANGELOG.md) for details.
Published to npm: [@reforge-com/cli@${{ needs.check-version.outputs.current-version }}](https://www.npmjs.com/package/@reforge-com/cli/v/${{ needs.check-version.outputs.current-version }})
draft: false
prerelease: false