|
9 | 9 |
|
10 | 10 | jobs: |
11 | 11 | check-version: |
12 | | - name: Check Version Change |
| 12 | + name: Check Version and Tag |
13 | 13 | runs-on: ubuntu-latest |
14 | 14 | outputs: |
15 | | - version_changed: ${{ steps.check.outputs.changed }} |
16 | | - new_version: ${{ steps.check.outputs.version }} |
| 15 | + current_version: ${{ steps.check.outputs.version }} |
| 16 | + tag_exists: ${{ steps.check.outputs.tag_exists }} |
17 | 17 | steps: |
18 | 18 | - uses: actions/checkout@v4 |
19 | 19 | with: |
20 | 20 | fetch-depth: 2 |
21 | 21 |
|
22 | | - - name: Check for version change |
| 22 | + - name: Get version and check if tag exists |
23 | 23 | id: check |
24 | 24 | run: | |
25 | | - PREV_VERSION=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version") |
26 | 25 | CURRENT_VERSION=$(node -p "require('./package.json').version") |
27 | | - echo "Previous version: $PREV_VERSION" |
28 | 26 | echo "Current version: $CURRENT_VERSION" |
| 27 | + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
29 | 28 |
|
30 | | - if [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then |
31 | | - echo "Version changed from $PREV_VERSION to $CURRENT_VERSION" |
32 | | - echo "changed=true" >> $GITHUB_OUTPUT |
33 | | - echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 29 | + TAG_NAME="v${CURRENT_VERSION}" |
| 30 | + if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then |
| 31 | + echo "Tag $TAG_NAME already exists" |
| 32 | + echo "tag_exists=true" >> $GITHUB_OUTPUT |
34 | 33 | else |
35 | | - echo "Version unchanged" |
36 | | - echo "changed=false" >> $GITHUB_OUTPUT |
| 34 | + echo "Tag $TAG_NAME does not exist" |
| 35 | + echo "tag_exists=false" >> $GITHUB_OUTPUT |
37 | 36 | fi |
38 | 37 |
|
39 | 38 | create-tag: |
40 | 39 | name: Create Tag |
41 | 40 | needs: check-version |
42 | | - if: needs.check-version.outputs.version_changed == 'true' |
| 41 | + if: needs.check-version.outputs.tag_exists == 'false' |
43 | 42 | runs-on: ubuntu-latest |
44 | 43 | permissions: |
45 | 44 | contents: write |
|
48 | 47 | with: |
49 | 48 | token: ${{ secrets.RELEASE_TOKEN }} |
50 | 49 |
|
51 | | - - name: Check if tag exists |
52 | | - id: tag-check |
53 | | - run: | |
54 | | - TAG_NAME="v${{ needs.check-version.outputs.new_version }}" |
55 | | - if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then |
56 | | - echo "Tag $TAG_NAME already exists" |
57 | | - echo "exists=true" >> $GITHUB_OUTPUT |
58 | | - else |
59 | | - echo "Tag $TAG_NAME does not exist" |
60 | | - echo "exists=false" >> $GITHUB_OUTPUT |
61 | | - fi |
62 | | -
|
63 | 50 | - name: Create and push tag |
64 | | - if: steps.tag-check.outputs.exists == 'false' |
65 | 51 | run: | |
66 | | - TAG_NAME="v${{ needs.check-version.outputs.new_version }}" |
| 52 | + TAG_NAME="v${{ needs.check-version.outputs.current_version }}" |
67 | 53 | git config user.name "github-actions[bot]" |
68 | 54 | git config user.email "github-actions[bot]@users.noreply.github.com" |
69 | 55 | git tag -a "$TAG_NAME" -m "Release $TAG_NAME" |
|
0 commit comments