|
| 1 | +name: 01 - Release Action |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +run-name: Release Action - ${{ github.actor }} |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + id-token: write # Required for signing the tag |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Required to get previous tags |
| 23 | + |
| 24 | + - name: Set up Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: 20 |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: npm install |
| 31 | + |
| 32 | + - name: Build |
| 33 | + run: npm run build |
| 34 | + |
| 35 | + - name: Commit dist |
| 36 | + run: | |
| 37 | + git config --local user.email "action@github.com" |
| 38 | + git config --local user.name "github-actions[bot]" |
| 39 | + git config set advice.addIgnoredFile false |
| 40 | + git add dist/ |
| 41 | + git commit -m "chore: update distributed files" || echo "No changes to commit" |
| 42 | + git push |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Check if version has changed |
| 47 | + id: check_version |
| 48 | + run: | |
| 49 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 50 | + echo CURRENT_VERSION=$CURRENT_VERSION >> "$GITHUB_OUTPUT" |
| 51 | + echo "Current version: $CURRENT_VERSION" |
| 52 | + PREVIOUS_TAG=$(git describe --abbrev=0 --tags 2>/dev/null || echo '') |
| 53 | + echo "Previous tag: $PREVIOUS_TAG" |
| 54 | + if [[ "$PREVIOUS_TAG" == "v$CURRENT_VERSION" ]]; then |
| 55 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 56 | + echo "Version has not changed, skipping tag creation" |
| 57 | + else |
| 58 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 59 | + echo "Version has changed, will create tag" |
| 60 | + fi |
| 61 | + env: |
| 62 | + GITHUB_OUTPUT: ${{ github.action_path }}/output.env |
| 63 | + |
| 64 | + - name: Create Git tag |
| 65 | + if: steps.check_version.outputs.changed == 'true' |
| 66 | + run: | |
| 67 | + TAG_NAME="v${{ steps.check_version.outputs.CURRENT_VERSION }}" |
| 68 | + git config --global user.email "renan-alm@github.com" |
| 69 | + git config --global user.name "Renan Alm" |
| 70 | + git tag -a "$TAG_NAME" -m "Release $TAG_NAME" |
| 71 | + git push origin "$TAG_NAME" |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments