|
| 1 | +name: Autobump |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + label-version-bump: |
| 9 | + name: Bump version based on PR label |
| 10 | + runs-on: ubuntu-20.04 |
| 11 | + if: | |
| 12 | + github.event.pull_request.merged |
| 13 | + && ( |
| 14 | + contains(github.event.pull_request.labels.*.name, 'bump patch') |
| 15 | + || contains(github.event.pull_request.labels.*.name, 'bump minor') |
| 16 | + || contains(github.event.pull_request.labels.*.name, 'bump major') |
| 17 | + ) |
| 18 | + steps: |
| 19 | + - name: Check out repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + ref: ${{ github.event.pull_request.base.ref }} |
| 23 | + token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }} |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - uses: pnpm/action-setup@v4 |
| 27 | + with: |
| 28 | + version: 8.x.x |
| 29 | + |
| 30 | + - name: Set up Rust |
| 31 | + run: | |
| 32 | + rustup update stable |
| 33 | + rustup default stable |
| 34 | +
|
| 35 | + - name: Install cargo-edit |
| 36 | + run: cargo install cargo-edit |
| 37 | + |
| 38 | + - name: Detect version bump type |
| 39 | + id: bump-type |
| 40 | + run: | |
| 41 | + BUMP_TYPE=null |
| 42 | + if [[ $BUMP_PATCH_PRESENT == 'true' ]]; then |
| 43 | + BUMP_TYPE=patch |
| 44 | + fi |
| 45 | + if [[ $BUMP_MINOR_PRESENT == 'true' ]]; then |
| 46 | + BUMP_TYPE=minor |
| 47 | + fi |
| 48 | + if [[ $BUMP_MAJOR_PRESENT == 'true' ]]; then |
| 49 | + BUMP_TYPE=major |
| 50 | + fi |
| 51 | + echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT" |
| 52 | + env: |
| 53 | + BUMP_PATCH_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump patch') }} |
| 54 | + BUMP_MINOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump minor') }} |
| 55 | + BUMP_MAJOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump major') }} |
| 56 | + |
| 57 | + - name: Determine new version |
| 58 | + id: versions |
| 59 | + if: steps.bump-type.outputs.bump-type != 'null' |
| 60 | + run: | |
| 61 | + NEW_VERSION=$(npx semver $OLD_VERSION -i ${{ steps.bump-type.outputs.bump-type }}) |
| 62 | + echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT" |
| 63 | + echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + - name: Update version in cargo.toml |
| 66 | + if: steps.bump-type.outputs.bump-type != 'null' |
| 67 | + run: | |
| 68 | + OLD_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "posthog-rs") | .version') |
| 69 | + cargo set-version --bump ${{ steps.bump-type.outputs.bump-type }} |
| 70 | + NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "posthog-rs") | .version') |
| 71 | +
|
| 72 | + - name: Update CHANGELOG.md |
| 73 | + run: | |
| 74 | + CHANGELOG_HEADING='## ${{ steps.versions.outputs.new-version }} - '$(date --iso-8601) |
| 75 | + CHANGELOG_POINTS=$(git log v${{ steps.versions.outputs.old-version }}..${{ github.event.pull_request.base.ref }} --pretty=format:%s --grep='^.*\d*)$' | sed -e 's/^/- /') |
| 76 | + mv CHANGELOG.md CHANGELOG.old.md |
| 77 | + echo -e "$CHANGELOG_HEADING\n\n$CHANGELOG_POINTS\n\n$(cat CHANGELOG.old.md)" > CHANGELOG.md |
| 78 | + rm CHANGELOG.old.md |
| 79 | +
|
| 80 | + - name: Update lockfile |
| 81 | + run: pnpm i |
| 82 | + |
| 83 | + - name: Commit bump |
| 84 | + if: steps.bump-type.outputs.bump-type != 'null' |
| 85 | + uses: EndBug/add-and-commit@v7 |
| 86 | + with: |
| 87 | + branch: ${{ github.event.pull_request.base.ref }} |
| 88 | + message: "chore: Bump version to ${{ steps.versions.outputs.new-version }}" |
| 89 | + github_token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }} |
0 commit comments