-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (101 loc) · 3.9 KB
/
release.yaml
File metadata and controls
107 lines (101 loc) · 3.9 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
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
with:
fetch-depth: 2
- name: Check if version changed
id: check
run: |
current_version=$(jq -r '.version' package.json)
previous_version=$(git show HEAD~1:package.json | jq -r '.version')
echo "current-version=$current_version" >> $GITHUB_OUTPUT
echo "previous-version=$previous_version" >> $GITHUB_OUTPUT
if [ "$current_version" != "$previous_version" ]; then
echo "Version changed from $previous_version to $current_version"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged: $current_version"
echo "changed=false" >> $GITHUB_OUTPUT
fi
# 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
# 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
- run: yarn bundle
- name: Publish to npm
run: |
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: 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/sdk-javascript/blob/main/CHANGELOG.md) for details.
Published to npm: [@reforge-com/javascript@${{ needs.check-version.outputs.current-version }}](https://www.npmjs.com/package/@reforge-com/javascript/v/${{ needs.check-version.outputs.current-version }})
draft: false
prerelease: false