Files
Nemera/.github/workflows/publish-release.yml

151 lines
6.8 KiB
YAML

name: Publish Release
# Runs only when the repository owner creates a release/x.y.z branch. The protected "release" environment supplies the Six Labors license and the pull request token, and requires approval.
# The repository ruleset restricts who can create release branches.
on:
create:
permissions:
contents: read
jobs:
publish:
if: github.event.ref_type == 'branch' && startsWith(github.ref_name, 'release/') && github.actor == github.repository_owner
runs-on: ubuntu-latest
timeout-minutes: 90
environment: release
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Validate release branch name
env:
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
if [[ ! "$RELEASE_BRANCH" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid release branch name. Use release/x.y.z." >&2
exit 1
fi
- name: Fetch master for the recording guard
run: git fetch --no-tags origin master:refs/remotes/origin/master
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.100'
- name: Restore Six Labors license
shell: bash
env:
SIXLABORS_LICENSE_KEY: ${{ secrets.SIXLABORS_LICENSE_KEY }}
run: printf '%s\n' "$SIXLABORS_LICENSE_KEY" > src/Nemera.Domain/sixlabors.lic
- name: Publish, verify, and record official release
env:
SixLaborsLicenseKey: ${{ secrets.SIXLABORS_LICENSE_KEY }}
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
release_version="${RELEASE_BRANCH#release/}"
dotnet msbuild build/build.proj -t:RecordBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:AllowBundledPluginsRecording=true -p:ReleaseBranch="$RELEASE_BRANCH" -p:Version="$release_version"
# Upload the verified archives before the image step, so a Docker failure does not discard successfully built archives.
- name: Upload release archives
uses: actions/upload-artifact@v4
with:
name: release-archives
path: bin/release/*
if-no-files-found: error
# Reuse the verified publish output, so the images contain exactly the plugin binaries whose hashes were recorded.
- name: Build release images
env:
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
release_version="${RELEASE_BRANCH#release/}"
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:ReusePublishedBundledPlugins=true -p:Version="$release_version"
- name: Upload bundled plugin manifest
uses: actions/upload-artifact@v4
with:
name: bundled-plugins-manifest
path: build/BundledPlugins.manifest
if-no-files-found: error
# The record job runs separately because it needs the pull request token to write to master, while the publish job stays read-only.
record-manifest:
needs: publish
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
steps:
# Use the PAT rather than GITHUB_TOKEN, so the pull request opened below triggers the normal CI workflows.
- uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
token: ${{ secrets.RELEASE_PR_TOKEN }}
- name: Validate release branch name
env:
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
if [[ ! "$RELEASE_BRANCH" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid release branch name. Use release/x.y.z." >&2
exit 1
fi
- name: Download bundled plugin manifest
uses: actions/download-artifact@v4
with:
name: bundled-plugins-manifest
path: recorded-manifest
# Merge into master's current file instead of overwriting it, so hashes recorded by earlier releases survive when master advanced after this branch was cut.
- name: Merge the released manifest into master
run: |
python3 - <<'PY'
from pathlib import Path
master_path = Path("build/BundledPlugins.manifest")
artifact_path = Path("recorded-manifest/BundledPlugins.manifest")
master_text = master_path.read_text()
existing_entries = {
line.strip().lower()
for line in master_text.splitlines()
if line.strip() and not line.strip().startswith("#")
}
new_entries = []
for line in artifact_path.read_text().splitlines():
entry = line.strip()
if not entry or entry.startswith("#") or entry.lower() in existing_entries:
continue
existing_entries.add(entry.lower())
new_entries.append(entry)
if new_entries:
separator = "" if master_text.endswith("\n") else "\n"
master_path.write_text(master_text + separator + "\n".join(new_entries) + "\n")
PY
- name: Create record-release pull request
env:
GH_TOKEN: ${{ secrets.RELEASE_PR_TOKEN }}
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
release_version="${RELEASE_BRANCH#release/}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
branch="other/record-release-$release_version"
git checkout -b "$branch"
git add build/BundledPlugins.manifest
# The list is append-only. Fail loudly if a merge or a rerun staged a deletion instead of relying on review to catch it.
if [[ -n "$(git diff --cached --numstat -- build/BundledPlugins.manifest | awk '$2 != 0')" ]]; then
echo "The bundled plugin trust manifest diff removes lines. The list is append-only." >&2
exit 1
fi
if git diff --cached --quiet; then
echo "The bundled plugin manifest is already up to date."
exit 0
fi
git commit -m "Records bundled plugin hashes for $release_version"
git push --force-with-lease --set-upstream origin "$branch"
gh pr create \
--base master \
--head "$branch" \
--title "Records bundled plugin hashes for $release_version" \
--body "This pull request records the published plugin hashes of the $release_version release in the bundled plugin trust list. The release artifacts already embed the current release's official plugin manifest. Merge this pull request to keep the $release_version plugin binaries Official in future releases. Run All Tests and the branch validators should pass before merging."