|
| 1 | +name: Version, tag and GitHub release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + - uses: actions/setup-node@v4 |
| 13 | + - name: Generate GitHub App Token |
| 14 | + id: generate-token |
| 15 | + uses: tibdex/github-app-token@v1 |
| 16 | + with: |
| 17 | + app_id: ${{ secrets.ARCHETYPE_GITHUB_APP_ID }} |
| 18 | + private_key: ${{ secrets.ARCHETYPE_GITHUB_APP_KEY }} |
| 19 | + |
| 20 | + - name: Check if version already exists |
| 21 | + id: version-check |
| 22 | + run: | |
| 23 | + package_version=$(node -p "require('./package.json').version") |
| 24 | + exists=$(gh api repos/${{ github.repository }}/releases/tags/v$package_version >/dev/null 2>&1 && echo "true" || echo "") |
| 25 | +
|
| 26 | + if [ -n "$exists" ]; |
| 27 | + then |
| 28 | + echo "Version v$package_version already exists" |
| 29 | + 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." |
| 30 | + echo "skipped=true" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "Version v$package_version does not exist. Creating release..." |
| 33 | + echo "skipped=false" >> $GITHUB_OUTPUT |
| 34 | + echo "tag=v$package_version" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ steps.generate-token.outputs.token }} |
| 38 | + - name: Setup git |
| 39 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 40 | + run: | |
| 41 | + git config --global user.name "github-actions[bot]" |
| 42 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 43 | + - name: Create Github Release |
| 44 | + uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 |
| 45 | + if: ${{ steps.version-check.outputs.skipped == 'false' }} |
| 46 | + with: |
| 47 | + name: ${{ steps.version-check.outputs.tag }} |
| 48 | + tag: ${{ steps.version-check.outputs.tag }} |
| 49 | + commit: ${{ github.ref_name }} |
| 50 | + token: ${{ steps.generate-token.outputs.token }} |
| 51 | + skipIfReleaseExists: true |
0 commit comments