|
| 1 | +name: bump-version-and-pr |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: "Version bump type" |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + default: patch |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + email: |
| 16 | + description: "Email ID of the tse-developer user account" |
| 17 | + type: string |
| 18 | + required: true |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + bump-and-pr: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v3 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Setup Node |
| 34 | + uses: actions/setup-node@v3 |
| 35 | + with: |
| 36 | + node-version: '20.19.4' |
| 37 | + registry-url: 'https://registry.npmjs.org' |
| 38 | + |
| 39 | + - name: Configure Git |
| 40 | + run: | |
| 41 | + git config user.name "tse-developer" |
| 42 | + git config user.email "${{ github.event.inputs.email }}" |
| 43 | +
|
| 44 | + - name: Bump version |
| 45 | + id: bump |
| 46 | + run: | |
| 47 | + NEW_VERSION=$(npm version "${{ github.event.inputs.bump }}" --no-git-tag-version) |
| 48 | + # npm version returns "vX.Y.Z" – strip the leading v |
| 49 | + NEW_VERSION=${NEW_VERSION#v} |
| 50 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 51 | + echo "Branch will be $NEW_VERSION" |
| 52 | +
|
| 53 | + - name: Install (lockfile refresh if needed) |
| 54 | + run: npm install --package-lock-only |
| 55 | + |
| 56 | + - name: Commit changes |
| 57 | + run: | |
| 58 | + BRANCH="${{ steps.bump.outputs.new_version }}" |
| 59 | + git checkout -b "$BRANCH" |
| 60 | + git status |
| 61 | + git add package.json package-lock.json |
| 62 | + git commit -m "chore: bump version to v${{ steps.bump.outputs.new_version }}" |
| 63 | +
|
| 64 | + - name: Push branch |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + run: | |
| 68 | + BRANCH="${{ steps.bump.outputs.new_version }}" |
| 69 | + git push origin "$BRANCH" |
| 70 | +
|
| 71 | + - name: Create Pull Request |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + run: | |
| 75 | + BRANCH="${{ steps.bump.outputs.new_version }}" |
| 76 | + BODY="## Summary: Bumped version to v${{ steps.bump.outputs.new_version }}" |
| 77 | + TITLE="chore: release v${{ steps.bump.outputs.new_version }}" |
| 78 | + gh pr create \ |
| 79 | + --title "$TITLE" \ |
| 80 | + --body "$BODY" \ |
| 81 | + --base main \ |
| 82 | + --head "$BRANCH" \ |
0 commit comments