|
| 1 | +name: Cut a new tag (also auto updates package.json and package-lock.json) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: 'Version bump type (patch, minor, major)' |
| 8 | + required: true |
| 9 | + default: 'patch' |
| 10 | + |
| 11 | +jobs: |
| 12 | + bump-version: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v3 |
| 18 | + |
| 19 | + - name: Set up Node.js |
| 20 | + uses: actions/setup-node@v3 |
| 21 | + with: |
| 22 | + node-version: '20' |
| 23 | + |
| 24 | + - name: Get triggering user's email |
| 25 | + run: | |
| 26 | + user_email=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/users/${{ github.actor }} | jq -r '.email') |
| 27 | + if [ -z "$user_email" ] || [ "$user_email" == "null" ]; then |
| 28 | + user_email="github-actions@github.com" |
| 29 | + fi |
| 30 | + echo "user_email=$user_email" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + - name: Configure Git with the triggering user's info |
| 33 | + run: | |
| 34 | + git config user.name "${{ github.actor }}" |
| 35 | + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" |
| 36 | +
|
| 37 | + - name: Bump version, update manifest, commit and tag |
| 38 | + run: | |
| 39 | + set -euo pipefail |
| 40 | +
|
| 41 | + npm install |
| 42 | +
|
| 43 | + # 1) Bump package.json + package-lock.json but DO NOT commit/tag yet |
| 44 | + npm version ${{ github.event.inputs.release_type }} --no-git-tag-version |
| 45 | +
|
| 46 | + # 2) Read the new version from package.json |
| 47 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 48 | + echo "New version is: $NEW_VERSION" |
| 49 | +
|
| 50 | + # 3) Update manifest.json's "version" field to match |
| 51 | + jq --arg v "$NEW_VERSION" '.version = $v' manifest.json > manifest.json.tmp |
| 52 | + mv manifest.json.tmp manifest.json |
| 53 | +
|
| 54 | + # 4) Commit everything and create an annotated tag |
| 55 | + git add package.json package-lock.json manifest.json |
| 56 | + git commit -m "chore: bump version to $NEW_VERSION" |
| 57 | + git tag -a "v$NEW_VERSION" -m "v$NEW_VERSION" |
| 58 | +
|
| 59 | + # 5) Push commit and tag |
| 60 | + git push --follow-tags |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments