-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (82 loc) · 2.94 KB
/
Copy pathonPushToMain.yml
File metadata and controls
90 lines (82 loc) · 2.94 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
# test
name: version, tag and github release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24.x'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Check if version already exists
id: version-check
env:
GH_TOKEN: ${{ github.token }}
run: |
package_version=$(node -p "require('./package.json').version")
tag="v$package_version"
echo "Checking for release: $tag"
exists=""
apiOutput=""
apiStatus=0
apiOutput=$(gh api repos/${{ github.repository }}/releases/tags/$tag 2>&1) || apiStatus=$?
echo "::group::gh api response"
echo "$apiOutput"
echo "Status: $apiStatus"
echo "::endgroup::"
if [ "$apiStatus" -eq 0 ]; then
exists="true"
fi
if [ -n "$exists" ];
then
echo "Version v$package_version already exists"
echo "::warning file=package.json,line=1::Version v$package_version already exists - no release will be created. If you want to create a new release, please update the version in package.json and push again."
echo "skipped=true" >> $GITHUB_OUTPUT
else
echo "Version v$package_version does not exist. Creating release..."
echo "skipped=false" >> $GITHUB_OUTPUT
echo "tag=v$package_version" >> $GITHUB_OUTPUT
fi
- name: Setup git
if: ${{ steps.version-check.outputs.skipped == 'false' }}
run: |
git config --global user.email ${{ secrets.GH_EMAIL }}
git config --global user.name ${{ secrets.GH_USERNAME }}
- name: Run build
if: ${{ steps.version-check.outputs.skipped == 'false' }}
run: |
npm install
npm run build
- name: Verify build
if: ${{ steps.version-check.outputs.skipped == 'false' }}
run: |
./bin/run.js
if [ $? -ne 0 ]; then
echo "Build verification failed. Please check the build output."
exit 1
fi
- name: Create Github Release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5
if: ${{ steps.version-check.outputs.skipped == 'false' && !env.ACT }}
with:
name: ${{ steps.version-check.outputs.tag }}
tag: ${{ steps.version-check.outputs.tag }}
commit: ${{ github.ref_name }}
skipIfReleaseExists: true
generateReleaseNotes: true
- name: Publish to npm
if: ${{ steps.version-check.outputs.skipped == 'false' && !env.ACT }}
run: |
npm publish