|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Bump Version & Update Changelog |
| 11 | + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'data-update') |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + |
| 22 | + - name: Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: '20' |
| 26 | + cache: 'npm' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: npm ci |
| 30 | + |
| 31 | + - name: Bump patch version |
| 32 | + id: bump |
| 33 | + run: | |
| 34 | + OLD_VERSION=$(node -p "require('./package.json').version") |
| 35 | + NEW_VERSION=$(npm version patch --no-git-tag-version) |
| 36 | + echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT |
| 37 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 38 | + echo "Bumped $OLD_VERSION -> $NEW_VERSION" |
| 39 | +
|
| 40 | + - name: Update CHANGELOG.md |
| 41 | + env: |
| 42 | + NEW_VERSION: ${{ steps.bump.outputs.new_version }} |
| 43 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 44 | + run: | |
| 45 | + DATE=$(date +%Y-%m-%d) |
| 46 | + ENTRY="## [${NEW_VERSION#v}] - $DATE\n\n### Changed\n- Updated timezone data from upstream database (PR #$PR_NUMBER)\n" |
| 47 | +
|
| 48 | + if [ -f CHANGELOG.md ]; then |
| 49 | + # Insert after the first line (# Changelog header) |
| 50 | + sed -i "0,/^## \[/s//$ENTRY\n## [/" CHANGELOG.md |
| 51 | + else |
| 52 | + printf "# Changelog\n\nAll notable changes to \`@countrystatecity/timezones\` will be documented in this file.\n\n$ENTRY" > CHANGELOG.md |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Build and test |
| 56 | + run: | |
| 57 | + npm run build |
| 58 | + npm test |
| 59 | +
|
| 60 | + - name: Commit and push |
| 61 | + env: |
| 62 | + NEW_VERSION: ${{ steps.bump.outputs.new_version }} |
| 63 | + run: | |
| 64 | + git config user.name "github-actions[bot]" |
| 65 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | + git add package.json package-lock.json CHANGELOG.md |
| 67 | + git commit -m "chore: release ${NEW_VERSION}" |
| 68 | + git push |
0 commit comments