|
2 | 2 | name: Publish
|
3 | 3 | on:
|
4 | 4 | push:
|
5 |
| - tags: |
6 |
| - - v* |
| 5 | + branches: |
| 6 | + - main |
| 7 | +permissions: |
| 8 | + contents: write |
7 | 9 | jobs:
|
8 | 10 | publish:
|
9 | 11 | runs-on: ubuntu-latest
|
10 | 12 | environment: Production
|
11 | 13 | steps:
|
12 | 14 | - uses: GitHubSecurityLab/actions-permissions/monitor@v1
|
13 | 15 | - uses: actions/checkout@v4
|
| 16 | + with: |
| 17 | + fetch-depth: 0 |
14 | 18 | - uses: actions/setup-node@v4
|
15 | 19 | with:
|
16 | 20 | node-version-file: package.json
|
17 | 21 | registry-url: "https://registry.npmjs.org"
|
18 | 22 | cache: "npm"
|
| 23 | + - name: Get version |
| 24 | + id: get-version |
| 25 | + shell: bash |
| 26 | + run: | |
| 27 | + set +e |
| 28 | +
|
| 29 | + VERSION=v$(jq -r '.version' < package.json) |
| 30 | + echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" |
| 31 | + - name: Check if version already exists |
| 32 | + id: check-version |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + set +e |
| 36 | +
|
| 37 | + git rev-parse "${{ steps.get-version.outputs.VERSION }}" >/dev/null 2>&1 |
| 38 | + if [[ $? -eq 0 ]]; then |
| 39 | + echo "VERSION_EXISTS=true" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "VERSION_EXISTS=false" >> "$GITHUB_OUTPUT" |
| 42 | + fi |
19 | 43 | - name: Build package
|
| 44 | + if: steps.check-version.outputs.VERSION_EXISTS == 'false' |
20 | 45 | run: |
|
21 | 46 | npm ci
|
22 | 47 | npm run build
|
23 | 48 | - name: Publish to NPM
|
| 49 | + if: steps.check-version.outputs.VERSION_EXISTS == 'false' |
24 | 50 | run: npm publish
|
25 | 51 | env:
|
26 | 52 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
27 |
| - - name: Publish Github release |
| 53 | + - name: Publish git tag |
| 54 | + if: steps.check-version.outputs.VERSION_EXISTS == 'false' |
| 55 | + run: | |
| 56 | + git config --global user.name 'github-actions[bot]' |
| 57 | + git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 58 | + git tag ${{ steps.get-version.outputs.VERSION }} |
| 59 | + git push origin --tags |
| 60 | + - name: Publish git release |
| 61 | + if: steps.check-version.outputs.VERSION_EXISTS == 'false' |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ github.token }} |
28 | 64 | run: |
|
29 |
| - gh release create ${{ github.ref }} --title "${{ github.ref }}" --notes "Release ${{ github.ref }}" --generate-notes |
| 65 | + gh release create ${{ github.env.VERSION }} --title "${{ github.env.VERSION }}" --generate-notes |
0 commit comments