Repository navigation
106 lines (92 loc) · 3.84 KB
/
Copy pathrelease.yml
File metadata and controls
106 lines (92 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Release
on:
push:
tags:
- "v*"
# The "Run workflow" button (Actions -> Release). It releases the version
# stack.yaml declares on main: it creates the v<version> tag and the release
# on the commit it ran from, then verifies and publishes exactly as a tag push
# does. For when a tag cannot be pushed from where the release is cut.
workflow_dispatch:
# One release at a time: two runs publishing the same version would race.
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
packages: write
jobs:
publish-package:
name: Publish package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Orun
uses: sourceplane/orun-action@v1.1.0
- name: Make helper scripts executable
run: chmod +x scripts/*.sh
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Derive release version
shell: bash
run: |
stack_version="$(awk '/^ version: /{print $2}' stack.yaml)"
test -n "${stack_version}"
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
# A dispatched release names its own tag, from main only.
if [ "${GITHUB_REF}" != "refs/heads/main" ]; then
echo "::error::Run the release from main, not ${GITHUB_REF}."
exit 1
fi
release_tag="v${stack_version}"
# A version is released from one commit. An existing tag on another
# commit means stack.yaml was not bumped; on this commit it is a
# re-run of this release, which carries on as a tag push would.
existing="$(git rev-list -n 1 "refs/tags/${release_tag}" 2>/dev/null || true)"
if [ -n "${existing}" ] && [ "${existing}" != "${GITHUB_SHA}" ]; then
echo "::error::${release_tag} already points at ${existing}. Bump metadata.version in stack.yaml to release ${GITHUB_SHA}."
exit 1
fi
else
release_tag="${GITHUB_REF_NAME}"
test "${stack_version}" = "${release_tag#v}"
fi
echo "STACK_VERSION=${stack_version}" >> "${GITHUB_ENV}"
echo "RELEASE_TAG=${release_tag}" >> "${GITHUB_ENV}"
- name: Verify catalog
run: ./scripts/verify.sh
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${RELEASE_TAG}" >/dev/null 2>&1; then
echo "Release ${RELEASE_TAG} already exists."
exit 0
fi
# --target names the commit: on a dispatched run it is where the new
# tag is created; on a tag push the tag already points there.
gh release create "${RELEASE_TAG}" \
--title "${RELEASE_TAG}" \
--target "${GITHUB_SHA}" \
--generate-notes
# Runs after the release so the tag and release notes are the record of
# record before the immutable artifact is pushed. The target is passed
# explicitly: with no ref, orun infers ghcr.io/<owner>/<repo>/<package>
# from the git remote, which is the wrong repository path.
- name: Publish OCI package
run: |
orun publish "ghcr.io/sourceplane/stack-tectonic:${STACK_VERSION}" \
--root . \
--version "${STACK_VERSION}"
- name: Confirm package is pullable
run: |
orun fetch "ghcr.io/sourceplane/stack-tectonic:${STACK_VERSION}" \
--output "${RUNNER_TEMP}/published" --overwrite
test -f "${RUNNER_TEMP}/published/stack.yaml"
echo "published $(ls "${RUNNER_TEMP}/published/compositions" | wc -l) composition(s)"