ci: fixexed tag release
This commit is contained in:
1 parent
1a6c6ad9f5
commit
6d6e67bbba
2 files changed
+100
-112
No files matched your search
@@ -43,117 +43,16 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '**[0-9]+.[0-9]+.[0-9]+*'
|
- '**[0-9]+.[0-9]+.[0-9]+*'
|
||||||
workflow_run:
|
|
||||||
workflows: ["build"]
|
|
||||||
branches: [master]
|
|
||||||
types: [completed]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-check:
|
|
||||||
runs-on: "ubuntu-22.04"
|
|
||||||
outputs:
|
|
||||||
should-release: ${{ steps.decide.outputs.should-release }}
|
|
||||||
publishing: ${{ steps.decide.outputs.publishing }}
|
|
||||||
tag: ${{ steps.decide.outputs.tag }}
|
|
||||||
tag-flag: ${{ steps.decide.outputs.tag-flag }}
|
|
||||||
release-commit: ${{ steps.decide.outputs.release-commit }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
fetch-tags: true
|
|
||||||
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
|
|
||||||
- id: decide
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
||||||
echo "should-release=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "publishing=false" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag-flag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "release-commit=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${{ github.event_name }}" == "workflow_run" && "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
|
|
||||||
echo "build workflow concluded with ${{ github.event.workflow_run.conclusion }}; skipping release."
|
|
||||||
echo "should-release=false" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "publishing=false" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag-flag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "release-commit=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${{ github.ref_type }}" == "tag" ]]; then
|
|
||||||
echo "should-release=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "publishing=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag-flag=--tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "release-commit=${{ github.sha }}" >> "$GITHUB_OUTPUT"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
version=$(awk '
|
|
||||||
$0 == "[package]" { in_package = 1; next }
|
|
||||||
/^\[/ && in_package { exit }
|
|
||||||
in_package && $1 == "version" {
|
|
||||||
gsub(/"/, "", $3)
|
|
||||||
print $3
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
' Cargo.toml)
|
|
||||||
|
|
||||||
if [[ -z "$version" ]]; then
|
|
||||||
echo "failed to read package version from Cargo.toml" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
latest=$(
|
|
||||||
git tag --list \
|
|
||||||
| sed -nE 's/^v?([0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?)$/\1/p' \
|
|
||||||
| sort -V \
|
|
||||||
| tail -n1
|
|
||||||
)
|
|
||||||
|
|
||||||
should_release=false
|
|
||||||
if [[ -z "$latest" ]]; then
|
|
||||||
should_release=true
|
|
||||||
elif [[ "$version" != "$latest" && "$(printf '%s\n%s\n' "$latest" "$version" | sort -V | tail -n1)" == "$version" ]]; then
|
|
||||||
should_release=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$should_release" == "true" ]]; then
|
|
||||||
tag="v${version}"
|
|
||||||
echo "Cargo.toml version ${version} is newer than latest tag ${latest:-<none>}; releasing ${tag}."
|
|
||||||
echo "should-release=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "publishing=true" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag-flag=--tag=${tag}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "release-commit=${{ github.event.workflow_run.head_sha || github.sha }}" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "Cargo.toml version ${version} is not newer than latest tag ${latest}; skipping release."
|
|
||||||
echo "should-release=false" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "publishing=false" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "tag-flag=" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "release-commit=${{ github.event.workflow_run.head_sha || github.sha }}" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run 'dist plan' (or host) to determine what tasks we need to do
|
# Run 'dist plan' (or host) to determine what tasks we need to do
|
||||||
plan:
|
plan:
|
||||||
needs:
|
|
||||||
- release-check
|
|
||||||
if: ${{ needs.release-check.outputs.should-release == 'true' }}
|
|
||||||
runs-on: "ubuntu-22.04"
|
runs-on: "ubuntu-22.04"
|
||||||
outputs:
|
outputs:
|
||||||
val: ${{ steps.plan.outputs.manifest }}
|
val: ${{ steps.plan.outputs.manifest }}
|
||||||
tag: ${{ needs.release-check.outputs.tag }}
|
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
|
||||||
tag-flag: ${{ needs.release-check.outputs.tag-flag }}
|
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
|
||||||
publishing: ${{ needs.release-check.outputs.publishing }}
|
publishing: ${{ !github.event.pull_request }}
|
||||||
release-commit: ${{ needs.release-check.outputs.release-commit }}
|
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
@@ -161,7 +60,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
ref: ${{ needs.release-check.outputs.release-commit }}
|
|
||||||
- name: Install dist
|
- name: Install dist
|
||||||
# we specify bash to get pipefail; it guards against the `curl` command
|
# we specify bash to get pipefail; it guards against the `curl` command
|
||||||
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
||||||
@@ -179,7 +77,7 @@ jobs:
|
|||||||
# but also really annoying to build CI around when it needs secrets to work right.)
|
# but also really annoying to build CI around when it needs secrets to work right.)
|
||||||
- id: plan
|
- id: plan
|
||||||
run: |
|
run: |
|
||||||
dist ${{ (needs.release-check.outputs.publishing == 'true' && format('host --steps=create --tag={0}', needs.release-check.outputs.tag)) || 'plan' }} --output-format=json > plan-dist-manifest.json
|
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
|
||||||
echo "dist ran successfully"
|
echo "dist ran successfully"
|
||||||
cat plan-dist-manifest.json
|
cat plan-dist-manifest.json
|
||||||
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||||
@@ -195,7 +93,7 @@ jobs:
|
|||||||
# Let the initial task tell us to not run (currently very blunt)
|
# Let the initial task tell us to not run (currently very blunt)
|
||||||
needs:
|
needs:
|
||||||
- plan
|
- plan
|
||||||
if: ${{ needs.plan.result == 'success' && fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
|
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
# Target platforms/runners are computed by dist in create-release.
|
# Target platforms/runners are computed by dist in create-release.
|
||||||
@@ -222,7 +120,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
ref: ${{ needs.plan.outputs.release-commit }}
|
|
||||||
- name: Install Rust non-interactively if not already installed
|
- name: Install Rust non-interactively if not already installed
|
||||||
if: ${{ matrix.container }}
|
if: ${{ matrix.container }}
|
||||||
run: |
|
run: |
|
||||||
@@ -287,7 +184,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
ref: ${{ needs.plan.outputs.release-commit }}
|
|
||||||
- name: Install cached dist
|
- name: Install cached dist
|
||||||
uses: actions/download-artifact@v7
|
uses: actions/download-artifact@v7
|
||||||
with:
|
with:
|
||||||
@@ -338,7 +234,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
ref: ${{ needs.plan.outputs.release-commit }}
|
|
||||||
- name: Install cached dist
|
- name: Install cached dist
|
||||||
uses: actions/download-artifact@v7
|
uses: actions/download-artifact@v7
|
||||||
with:
|
with:
|
||||||
@@ -381,7 +276,7 @@ jobs:
|
|||||||
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
|
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
|
||||||
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
|
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
|
||||||
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
|
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
|
||||||
RELEASE_COMMIT: "${{ needs.plan.outputs.release-commit }}"
|
RELEASE_COMMIT: "${{ github.sha }}"
|
||||||
run: |
|
run: |
|
||||||
# Write and read notes from a file to avoid quoting breaking things
|
# Write and read notes from a file to avoid quoting breaking things
|
||||||
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
|
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
|
||||||
@@ -507,4 +402,3 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
ref: ${{ needs.plan.outputs.release-commit }}
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
name: tag release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["build"]
|
||||||
|
branches: [master]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: tag-release
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag-release:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
fetch-tags: true
|
||||||
|
ref: ${{ github.event.workflow_run.head_sha || 'master' }}
|
||||||
|
|
||||||
|
- name: decide release tag
|
||||||
|
id: release
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
version=$(awk '
|
||||||
|
$0 == "[package]" { in_package = 1; next }
|
||||||
|
/^\[/ && in_package { exit }
|
||||||
|
in_package && $1 == "version" {
|
||||||
|
gsub(/"/, "", $3)
|
||||||
|
print $3
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
' Cargo.toml)
|
||||||
|
|
||||||
|
if [[ -z "$version" ]]; then
|
||||||
|
echo "failed to read package version from Cargo.toml" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
latest=$(
|
||||||
|
git tag --list \
|
||||||
|
| sed -nE 's/^v?([0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?)$/\1/p' \
|
||||||
|
| sort -V \
|
||||||
|
| tail -n1
|
||||||
|
)
|
||||||
|
|
||||||
|
should_release=false
|
||||||
|
if [[ -z "$latest" ]]; then
|
||||||
|
should_release=true
|
||||||
|
elif [[ "$version" != "$latest" && "$(printf '%s\n%s\n' "$latest" "$version" | sort -V | tail -n1)" == "$version" ]]; then
|
||||||
|
should_release=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
tag="v${version}"
|
||||||
|
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "latest=${latest}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "should-release=${should_release}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
if [[ "$should_release" == "true" ]]; then
|
||||||
|
echo "Cargo.toml version ${version} is newer than latest tag ${latest:-<none>}; creating ${tag}."
|
||||||
|
else
|
||||||
|
echo "Cargo.toml version ${version} is not newer than latest tag ${latest}; skipping release."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: create release tag
|
||||||
|
if: ${{ steps.release.outputs.should-release == 'true' }}
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
|
TAG_NAME: ${{ steps.release.outputs.tag }}
|
||||||
|
TAG_SHA: ${{ steps.release.outputs.sha }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [[ -z "${GH_TOKEN}" ]]; then
|
||||||
|
echo "RELEASE_TOKEN is required so the created tag can trigger the generated release workflow." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
gh api "repos/${{ github.repository }}/git/refs" \
|
||||||
|
-f "ref=refs/tags/${TAG_NAME}" \
|
||||||
|
-f "sha=${TAG_SHA}"
|
||||||
Reference in new issue
Block a user