|
| 1 | +#--------------------------------------------------------- |
| 2 | +# - Create a semantical release |
| 3 | +# - Set latest tag |
| 4 | +#--------------------------------------------------------- |
| 5 | + name: Bump version |
| 6 | + |
| 7 | + on: |
| 8 | + workflow_dispatch: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - next |
| 12 | + - next-major |
| 13 | + |
| 14 | + jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + # required antecedent |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + |
| 24 | + - name: Setup Node.js environment |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: '20.9.0' |
| 28 | + |
| 29 | + - name: Install npm dev dependencies |
| 30 | + run: npm install |
| 31 | + |
| 32 | + - name: Get current version |
| 33 | + id: current_version |
| 34 | + run: | |
| 35 | + echo "CURRENT_VERSION=$(python -c 'from __version__ import __version__; print(__version__)')" >> $GITHUB_ENV |
| 36 | + env: |
| 37 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 38 | + |
| 39 | + - name: Get next version |
| 40 | + id: next_version |
| 41 | + run: | |
| 42 | + echo "NEXT_VERSION=$(npx semantic-release --dry-run | awk '/The next release version is/{print $NF}')" >> $GITHUB_ENV |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 45 | + |
| 46 | + - name: Check versions |
| 47 | + id: check_versions |
| 48 | + run: | |
| 49 | + if [ "$CURRENT_VERSION" != "$NEXT_VERSION" ]; then |
| 50 | + echo "::set-output name=version_changed::true" |
| 51 | + else |
| 52 | + echo "::set-output name=version_changed::false" |
| 53 | + fi |
| 54 | + env: |
| 55 | + CURRENT_VERSION: ${{ env.CURRENT_VERSION }} |
| 56 | + NEXT_VERSION: ${{ env.NEXT_VERSION }} |
| 57 | + |
| 58 | + - name: Update __version__ |
| 59 | + if: steps.check_versions.outputs.version_changed == 'true' |
| 60 | + id: update_version |
| 61 | + run: | |
| 62 | + echo "__version__ = '${{ env.NEXT_VERSION }}'" > __version__.py |
| 63 | + git config --local user.email "[email protected]" |
| 64 | + git config --local user.name "GitHub Action" |
| 65 | + git add __version__.py |
| 66 | + git commit -m "chore: [gh] Update __version__.py to ${{ env.NEXT_VERSION }} [skip ci]" |
| 67 | + git push https://${{ secrets.PAT }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }} |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 70 | + CURRENT_VERSION: ${{ env.CURRENT_VERSION }} |
| 71 | + NEXT_VERSION: ${{ env.NEXT_VERSION }} |
0 commit comments