CI: publish a Gitea release naming the IPCR image and digest on v* tags
Build and Push Docker Image / build (push) Successful in 1m7s
Build and Push Docker Image / build (push) Successful in 1m7s
This commit is contained in:
@@ -36,7 +36,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write # the release step below
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
@@ -82,9 +82,48 @@ jobs:
|
||||
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
id: build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
# Gitea's Packages tab only lists images in Gitea's own registry, so a v* tag gets a
|
||||
# release instead, naming the image it shipped. The digest line is the one to trust:
|
||||
# ipcr 1.7.1 can drop some of the tags pushed together (see the tag list).
|
||||
- name: Publish the Gitea release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||
TAG: ${{ github.ref_name }}
|
||||
SHA: ${{ github.sha }}
|
||||
DIGEST: ${{ steps.build.outputs.digest }}
|
||||
TAGS: ${{ steps.meta.outputs.tags }}
|
||||
PULL: ipcr-watch.nsl.sh/ipns/metadec.eth/${{ env.IMAGE_NAME }}
|
||||
run: |
|
||||
node -e '
|
||||
const e = process.env, ver = e.TAG.replace(/^v/, "");
|
||||
const tags = e.TAGS.split("\n").filter(Boolean).map(t => "`" + t.split(":").pop() + "`");
|
||||
const body = [
|
||||
"**Image** (anonymous pull):",
|
||||
"```", `docker pull ${e.PULL}:${ver}`, "```",
|
||||
"Pinned by digest:",
|
||||
"```", `${e.PULL}@${e.DIGEST}`, "```",
|
||||
`Tags pushed: ${tags.join(", ")} · commit ${e.SHA.slice(0, 7)}`,
|
||||
].join("\n");
|
||||
console.log(JSON.stringify({ tag_name: e.TAG, name: e.TAG, body }));
|
||||
' > /tmp/release.json
|
||||
auth="Authorization: token $TOKEN"
|
||||
code=$(curl -s -o /tmp/existing.json -w '%{http_code}' -H "$auth" "$API/releases/tags/$TAG")
|
||||
if [ "$code" = 200 ]; then
|
||||
id=$(node -p 'require("/tmp/existing.json").id')
|
||||
method=PATCH url="$API/releases/$id"
|
||||
else
|
||||
method=POST url="$API/releases"
|
||||
fi
|
||||
code=$(curl -s -o /tmp/out.json -w '%{http_code}' -X "$method" -H "$auth" \
|
||||
-H 'Content-Type: application/json' --data @/tmp/release.json "$url")
|
||||
case "$code" in 2*) echo "release $TAG: $method $code" ;; *) cat /tmp/out.json; exit 1 ;; esac
|
||||
|
||||
Reference in New Issue
Block a user