Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 4 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ jobs:
echo "branch=${release_branch}" >> "$GITHUB_OUTPUT"

- name: Inspect release refs
id: refs
shell: bash
run: |
set -euo pipefail

version="${{ steps.version.outputs.next }}"
branch="${{ steps.version.outputs.branch }}"

if git ls-remote --exit-code --tags origin "refs/tags/${version}" >/dev/null 2>&1; then
echo "Tag ${version} already exists." >&2
Expand All @@ -109,56 +107,30 @@ jobs:
exit 1
fi

if git ls-remote --exit-code --heads origin "${branch}" >/dev/null 2>&1; then
echo "branch_exists=true" >> "$GITHUB_OUTPUT"
else
echo "branch_exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Create or reuse release branch
id: branch
- name: Create release branch
shell: bash
run: |
set -euo pipefail

version="${{ steps.version.outputs.next }}"
branch="${{ steps.version.outputs.branch }}"
branch_exists="${{ steps.refs.outputs.branch_exists }}"

if [[ "${branch_exists}" == "true" ]]; then
git fetch origin "${branch}"
git switch -C "${branch}" "origin/${branch}"

branch_version="$(tr -d '[:space:]' < VERSION)"
if [[ "${branch_version}" != "${version}" ]]; then
echo "Existing ${branch} has VERSION ${branch_version}, expected ${version}." >&2
exit 1
fi

echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
fi

# Branch from development so the release includes all new changes
# Always (re)create from development so the release includes all
# new changes — even on a rerun where the branch already exists.
git fetch origin development
git switch -c "${branch}" origin/development

# Merge main to incorporate any commits not on development
# (e.g. previous release chore commits)
git merge origin/main --no-edit

echo "created=true" >> "$GITHUB_OUTPUT"

- name: Validate build
if: steps.branch.outputs.created == 'true'
shell: bash
run: |
set -euo pipefail
rm -rf build
./build.sh

- name: Update CHANGELOG
if: steps.branch.outputs.created == 'true'
id: changelog
shell: bash
run: |
Expand Down Expand Up @@ -211,7 +183,6 @@ jobs:
mv "${tmp}" CHANGELOG.md

- name: Commit and push release changes
if: steps.branch.outputs.created == 'true'
shell: bash
run: |
set -euo pipefail
Expand All @@ -222,7 +193,7 @@ jobs:
printf '%s\n' "${version}" > VERSION
git add VERSION CHANGELOG.md
git commit -m "chore(release): ${version}" -m "- bump VERSION to ${version}" -m "- update CHANGELOG.md"
git push --set-upstream origin "${branch}"
git push --force-with-lease --set-upstream origin "${branch}"

- name: Open or reuse release pull request
id: pr
Expand Down
Loading