Skip to content

Commit 945701d

Browse files
authored
Merge pull request #15 from parzh/fix/fix-automatic-publishing-on-version-update
Fix automatic publishing on version update
2 parents a235f73 + 4659e81 commit 945701d

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

.github/workflows/check-version-update-on-release.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
branches:
66
- 'release/*'
77

8+
defaults:
9+
run:
10+
shell: bash -o pipefail {0}
11+
812
jobs:
913
check:
1014
runs-on: ubuntu-latest

.github/workflows/test-publish.yaml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- main
1010

11+
defaults:
12+
run:
13+
shell: bash -o pipefail {0}
14+
1115
jobs:
1216
audit:
1317
name: Audit
@@ -74,40 +78,51 @@ jobs:
7478
name: coverage
7579
path: coverage
7680

77-
publish:
81+
detect_version_update:
7882
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
79-
name: Publish on version update
80-
needs:
81-
- test
82-
permissions:
83-
contents: read
84-
id-token: write
83+
name: Detect version update
8584
runs-on: ubuntu-latest
85+
outputs:
86+
detected: ${{ steps.detect.outputs.detected }}
8687
steps:
8788
- uses: actions/checkout@v5
88-
- uses: actions/setup-node@v5
8989
with:
90-
node-version-file: '/.nvmrc'
91-
registry-url: 'https://registry.npmjs.org'
90+
fetch-depth: 2
9291

93-
- name: Check for version update
94-
id: check_version
92+
- id: detect
9593
run: |
9694
CURRENT_VERSION=$(jq -r .version package.json)
9795
PREVIOUS_VERSION=$(git show HEAD~1:package.json | jq -r .version)
9896
9997
if [[ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]]; then
100-
echo "version_updated=true" >> $GITHUB_OUTPUT
98+
echo "Version has been updated. Proceeding to publish."
99+
echo "detected=true" >> $GITHUB_OUTPUT
100+
else
101+
echo "Version has not changed. Skipping publish."
102+
echo "detected=false" >> $GITHUB_OUTPUT
101103
fi
102104
103-
- if: steps.check_version.outputs.version_updated
104-
run: npm ci
105+
publish:
106+
name: Publish
107+
needs:
108+
- test
109+
- detect_version_update
110+
if: needs.detect_version_update.outputs.detected == 'true'
111+
permissions:
112+
contents: read
113+
id-token: write
114+
runs-on: ubuntu-latest
115+
steps:
116+
- uses: actions/checkout@v5
117+
- uses: actions/setup-node@v5
118+
with:
119+
node-version-file: '/.nvmrc'
120+
registry-url: 'https://registry.npmjs.org'
105121

106-
- if: steps.check_version.outputs.version_updated
107-
run: npm run build
122+
- run: npm ci
123+
- run: npm run build
108124

109-
- if: steps.check_version.outputs.version_updated
110-
name: Publish
125+
- name: Publish
111126
env:
112127
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
113128
run: |

0 commit comments

Comments
 (0)