|
| 1 | +name: Tag and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + tag-and-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 # fetch all tags |
| 19 | + |
| 20 | + - name: Get version from package.json |
| 21 | + id: get_version |
| 22 | + run: | |
| 23 | + VERSION=$(jq -r .version package.json) |
| 24 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 25 | +
|
| 26 | + - name: Check if tag exists |
| 27 | + id: check_tag |
| 28 | + run: | |
| 29 | + TAG="v${{ steps.get_version.outputs.version }}" |
| 30 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 31 | + echo "Tag $TAG exists. Skipping release." |
| 32 | + echo "tag_exists=true" >> $GITHUB_OUTPUT |
| 33 | + else |
| 34 | + echo "tag_exists=false" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Create and push tag |
| 38 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 39 | + run: | |
| 40 | + TAG="v${{ steps.get_version.outputs.version }}" |
| 41 | + git config user.name "github-actions[bot]" |
| 42 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 43 | + git tag "$TAG" |
| 44 | + git push origin "$TAG" |
| 45 | +
|
| 46 | + - name: Setup Node |
| 47 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '22' |
| 51 | + |
| 52 | + - name: Install dependencies |
| 53 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 54 | + run: npm ci |
| 55 | + |
| 56 | + - name: Build library |
| 57 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 58 | + run: npm run build:lib |
| 59 | + |
| 60 | + - name: Package build output |
| 61 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 62 | + run: npm pack |
| 63 | + |
| 64 | + - name: Create GitHub Release |
| 65 | + if: steps.check_tag.outputs.tag_exists == 'false' |
| 66 | + uses: softprops/action-gh-release@v2 |
| 67 | + with: |
| 68 | + tag_name: ${{ steps.get_version.outputs.version }} |
| 69 | + files: '*.tgz' |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments