Skip to content

Rename release.yml to release.yaml #34

Rename release.yml to release.yaml

Rename release.yml to release.yaml #34

name: Autobump
on:
pull_request:
types: [closed]
jobs:
label-version-bump:
name: Bump version based on PR label
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged
&& (
contains(github.event.pull_request.labels.*.name, 'bump patch')
|| contains(github.event.pull_request.labels.*.name, 'bump minor')
|| contains(github.event.pull_request.labels.*.name, 'bump major')
|| contains(github.event.pull_request.labels.*.name, 'release')
)
steps:
- name: Get app token
id: app-token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
with:
app-id: ${{ secrets.GH_APP_POSTHOG_RS_RELEASER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_RS_RELEASER_PRIVATE_KEY }}
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- name: Set up Rust
run: |
rustup update stable
rustup default stable
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Detect version bump type
id: bump-type
run: |
BUMP_TYPE=null
if [[ $BUMP_PATCH_PRESENT == 'true' ]]; then
BUMP_TYPE=patch
fi
if [[ $BUMP_MINOR_PRESENT == 'true' ]]; then
BUMP_TYPE=minor
fi
if [[ $BUMP_MAJOR_PRESENT == 'true' ]]; then
BUMP_TYPE=major
fi
echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT"
env:
BUMP_PATCH_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump patch') }}
BUMP_MINOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump minor') }}
BUMP_MAJOR_PRESENT: ${{ contains(github.event.pull_request.labels.*.name, 'bump major') }}
- name: Update version in cargo.toml
id: versions
env:
BUMP_TYPE: ${{ steps.bump-type.outputs.bump-type }}
run: |
OLD_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "posthog-rs") | .version')
if [[ "$BUMP_TYPE" != 'null' ]]; then
cargo set-version --bump "$BUMP_TYPE"
NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "posthog-rs") | .version')
echo "Upgraded from $OLD_VERSION to $NEW_VERSION"
else
NEW_VERSION=$OLD_VERSION
echo "No version bump, using current version $NEW_VERSION"
fi
echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Update CHANGELOG.md
if: steps.bump-type.outputs.bump-type != 'null'
env:
NEW_VERSION: ${{ steps.versions.outputs.new-version }}
OLD_VERSION: ${{ steps.versions.outputs.old-version }}
BASE_COMMIT: ${{ github.event.pull_request.base.ref }}
run: |
CHANGELOG_HEADING="## $NEW_VERSION - $(date --iso-8601)"
CHANGELOG_POINTS="$(git log v$OLD_VERSION..$BASE_COMMIT --pretty=format:%s --grep='^.*[0-9])$' | sed -e 's/^/- /')"
mv CHANGELOG.md CHANGELOG.old.md
echo -e "$CHANGELOG_HEADING\n\n$CHANGELOG_POINTS\n\n$(cat CHANGELOG.old.md)" > CHANGELOG.md
rm CHANGELOG.old.md
- name: Commit bump
if: steps.bump-type.outputs.bump-type != 'null'
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9
with:
branch: ${{ github.event.pull_request.base.ref }}
message: "chore: Bump version to ${{ steps.versions.outputs.new-version }}"
github_token: ${{ steps.app-token.outputs.token }}
- name: Create and push tag
if: contains(github.event.pull_request.labels.*.name, 'release')
run: |
git tag "v${{ steps.versions.outputs.new-version }}"
git push origin "v${{ steps.versions.outputs.new-version }}"