|
| 1 | +name: Bump version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + bump: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + fetch-depth: 0 # https://stackoverflow.com/a/67201604/15183871 |
| 15 | + |
| 16 | + - name: Setup Node |
| 17 | + uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: 22 |
| 20 | + cache: 'npm' |
| 21 | + |
| 22 | + - name: Compute release tag |
| 23 | + id: compute_tag |
| 24 | + run: | |
| 25 | + TAG=$(echo $(git tag | grep -o $(date '+%Y.%-m.') | wc -l) + 1 | bc) |
| 26 | + echo "next=$(date '+%Y.%-m.')$TAG" >> $GITHUB_OUTPUT |
| 27 | +
|
| 28 | + - name: Update version in package.json and package-lock.json |
| 29 | + run: | |
| 30 | + npm version ${{ steps.compute_tag.outputs.next }} --no-git-tag-version |
| 31 | +
|
| 32 | + - name: Update version in app.json |
| 33 | + run: | |
| 34 | + NEW_VERSION=${{ steps.compute_tag.outputs.next }} |
| 35 | + jq --arg v "$NEW_VERSION" '.expo.version = $v' app.json > tmp.$$.json && mv tmp.$$.json app.json |
| 36 | +
|
| 37 | + - name: Check unreleased changes |
| 38 | + run: | |
| 39 | + CHANGES=$(awk '/^## \[unreleased\]/{flag=1;next}/^## \[/{flag=0}flag' CHANGELOG.md | grep -v '^\s*$' || true) |
| 40 | + if [ -z "$CHANGES" ]; then |
| 41 | + echo "🛑 No changes under [unreleased], skipping version bump." |
| 42 | + exit 0 |
| 43 | + else |
| 44 | + echo "✅ Changes detected under [unreleased], proceeding with bump." |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Update CHANGELOG.md |
| 48 | + run: | |
| 49 | + NEW_VERSION=${{ steps.compute_tag.outputs.next }} |
| 50 | + PREV_TAG=$(git tag --sort=-creatordate | grep -v "$NEW_VERSION" | head -n 1) |
| 51 | + TODAY=$(date +%Y-%m-%d) |
| 52 | + sed -i "/^\[unreleased\]:/c\[unreleased]: https://github.com/coworking-metz/mobile-app/compare/$NEW_VERSION...main\n[$NEW_VERSION]: https://github.com/coworking-metz/mobile-app/compare/$PREV_TAG...$NEW_VERSION" CHANGELOG.md |
| 53 | + awk -v v="$NEW_VERSION" -v d="$TODAY" ' |
| 54 | + /^## \[unreleased\]/ { |
| 55 | + print; |
| 56 | + print ""; |
| 57 | + print "## [" v "] - " d; |
| 58 | + next |
| 59 | + } |
| 60 | + { print } |
| 61 | + ' CHANGELOG.md > tmp.$$.md && mv tmp.$$.md CHANGELOG.md |
| 62 | +
|
| 63 | + - name: Commit and tag |
| 64 | + run: | |
| 65 | + NEW_VERSION=${{ steps.compute_tag.outputs.next }} |
| 66 | + git config user.name "${{ github.actor }}" |
| 67 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 68 | + git add app.json package.json package-lock.json CHANGELOG.md |
| 69 | + git commit -m "chore(version): update to $NEW_VERSION" |
| 70 | + git tag -a $NEW_VERSION -m "$NEW_VERSION" |
| 71 | + git log -n 5 --oneline --decorate |
| 72 | +
|
| 73 | + # - name: Push commit and tags |
| 74 | + # run: | |
| 75 | + # git push origin main |
| 76 | + # git push origin --tags |
0 commit comments