-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |