Skip to content

Commit

Permalink
Add versioning action (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi authored Apr 18, 2023
1 parent 5f77549 commit 11fdc17
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Versioning
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
versioning:
name: 'Versioning'
runs-on: ubuntu-22.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
fetch-depth: 0
- name: Setup git
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git config push.default current
- run: bash -e ./.github/workflows/versioning/main.sh
26 changes: 26 additions & 0 deletions .github/workflows/versioning/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -eu

version_string=$(jq -r '.version' package.json)
pr=$( (git log --oneline @...v"$version_string" || git log --oneline) | sed -nE 's/.+\((#[0-9]+)\)$/\1/p')
labels=$( echo "$pr" | xargs -n1 gh pr view --json labels -q '.labels[].name')
mapfile -t version < <(printf '%s\n' "${version_string//./$'\n'}")
if printf '%s\n' "${labels[@]}" | grep -qx 'semver:major'; then
((++version[0]))
version[1]=0
version[2]=0
elif printf '%s\n' "${labels[@]}" | grep -qx 'semver:minor'; then
((++version[1]))
version[2]=0
elif printf '%s\n' "${labels[@]}" | grep -qx 'semver:patch'; then
((++version[2]))
elif printf '%s\n' "${labels[@]}" | grep -qx 'semver:none'; then
exit 0
fi
new_version_string=$(printf ".%s" "${version[@]}")
new_version_string=${new_version_string:1}
git switch -C release
VERSION=$new_version_string perl -i -pe 's/( "version": ").+/\1$ENV{VERSION}",/ if !$done; $done ||= $&' package.json
echo -e "Release v${new_version_string}\n\nPR:\n${pr}" | git commit --no-gpg-sign -a --file=-
git push -f
gh pr create --base main --fill --label release || echo -e "PR:\n${pr}" | gh pr edit --title "Release v${new_version_string}" --body-file -
gh pr merge --auto --delete-branch --squash

0 comments on commit 11fdc17

Please sign in to comment.