Skip to content

Commit f63c559

Browse files
committed
Add OCI artifact publishing to release workflow
1 parent 61de14f commit f63c559

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ on:
66
- 'v*.*.*'
77

88
jobs:
9-
goreleaser:
10-
name: GoReleaser
9+
release:
10+
name: Release
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write
14-
pull-requests: write
14+
packages: write
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v4
@@ -31,3 +31,51 @@ jobs:
3131
args: release --clean
3232
env:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Setup ORAS
36+
uses: oras-project/setup-oras@v1
37+
with:
38+
version: latest
39+
40+
- name: Login to GHCR
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: echo "$GH_TOKEN" | oras login ghcr.io -u "${{ github.actor }}" --password-stdin
44+
45+
- name: Push binaries to GHCR as OCI artifacts
46+
env:
47+
TAG: ${{ github.ref_name }}
48+
shell: bash
49+
run: |
50+
set -euo pipefail
51+
shopt -s nullglob
52+
53+
OWNER="${{ github.repository_owner }}"
54+
OWNER_LC=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
55+
TAG="${TAG:-${{ github.ref_name }}}"
56+
REV="${{ github.sha }}"
57+
58+
for d in cmd/*; do
59+
[ -d "$d" ] || continue
60+
plugin="$(basename "$d")"
61+
62+
for binpath in "dist/${plugin}_*/${plugin}" "dist/${plugin}_*/${plugin}.exe"; do
63+
for bin in $binpath; do
64+
[ -f "$bin" ] || continue
65+
dir="$(basename "$(dirname "$bin")")"
66+
osarch="$(echo "$dir" | sed -E "s/^${plugin}_([A-Za-z0-9-]+)_([A-Za-z0-9-]+).*/\1-\2/")"
67+
ref="ghcr.io/${OWNER_LC}/${plugin}:${TAG}-${osarch}"
68+
fname="$(basename "$bin")"
69+
70+
oras push --artifact-type application/octet-stream \
71+
--annotation "org.opencontainers.image.title=${fname}" \
72+
--annotation "org.opencontainers.image.version=${TAG}" \
73+
--annotation "org.opencontainers.image.revision=${REV}" \
74+
--annotation "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
75+
--annotation "org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}/releases/tag/${TAG}" \
76+
--annotation "org.opencontainers.image.os=${osarch%-*}" \
77+
--annotation "org.opencontainers.image.architecture=${osarch#*-}" \
78+
"$ref" "$bin:application/octet-stream"
79+
done
80+
done
81+
done

0 commit comments

Comments
 (0)