Files
gentoo-zh/.github/workflows/autobump-env.yml
T
Zakk 3b3edd4462 .github: use one naming and formatting style across workflows
Workflow names now match their file stems, so the Actions list and the
files read the same; generate-deps-relation-r1.yml becomes
deps-table.yml after the branch it maintains. Steps are lowercase and
verb-first, every step is named, and the autobump-rb checkout has one
name everywhere.

Also use 4-space step indentation, fromJSON, bare if: expressions,
github.actor for every ghcr login, uppercase env names, and the
GITHUB_REPOSITORY and GITHUB_REPOSITORY_OWNER variables the runner
already sets instead of REPO and OWNER copies. No behaviour changes.

Signed-off-by: Zakk <zakk@gentoozh.org>
2026-10-11 04:30:43 +11:00

128 lines
4.1 KiB
YAML

# Tagged by ref so a branch test never overwrites the image the scheduled runs pull.
name: autobump-env
on:
workflow_call:
inputs:
force:
description: rebuild even if today's image exists
type: boolean
default: false
date:
description: use the image of an earlier day (YYYYMMDD); it must still be kept
type: string
default: ''
outputs:
image:
description: the image the bump workers run in
value: ${{ jobs.build.outputs.image }}
workflow_dispatch:
inputs:
force:
description: rebuild even if today's image exists
type: boolean
default: true
date:
description: use the image of an earlier day (YYYYMMDD); it must still be kept
type: string
default: ''
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 120
outputs:
image: ${{ steps.existing.outputs.ref }}
steps:
- name: checkout
uses: actions/checkout@v7
# ghcr takes neither an uppercase name nor the characters a git ref may carry
- name: set image name
id: image
env:
REF: ${{ github.ref_name }}
DAY: ${{ inputs.date }}
run: |
case "$DAY" in ''|[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) ;;
*) echo "date must be YYYYMMDD: $DAY" >&2; exit 1;; esac
owner=${GITHUB_REPOSITORY_OWNER,,}
tag=$(printf '%s' "$REF" | tr 'A-Z' 'a-z' | tr -c 'a-z0-9._-' '-')
echo "ref=ghcr.io/$owner/autobump-env:$tag-${DAY:-$(date -u +%Y%m%d)}" >> "$GITHUB_OUTPUT"
echo "base=ghcr.io/$owner/stage3:amd64-desktop-openrc" >> "$GITHUB_OUTPUT"
- name: log in to ghcr
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: look for the image
id: existing
env:
REF: ${{ steps.image.outputs.ref }}
DAY: ${{ inputs.date }}
FORCE: ${{ inputs.force }}
run: |
use=$REF
# stdout is the manifest, stderr is why it is not there - keep the second
if docker manifest inspect "$REF" > /dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
elif [ -n "$DAY" ]; then
# an earlier day cannot be rebuilt: its tree and binpkgs are gone
echo "no image for $DAY: $REF" >&2
exit 1
elif [ "$FORCE" != true ]; then
# daily builds today's image; a bump run before it, or after it failed, takes the newest kept one
for back in 1 2; do
old=${REF%-*}-$(date -u -d "$back days ago" +%Y%m%d)
if docker manifest inspect "$old" > /dev/null; then
use=$old
echo "exists=true" >> "$GITHUB_OUTPUT"
break
fi
done
fi
echo "ref=$use" >> "$GITHUB_OUTPUT"
# no build cache: the point of rebuilding is to pick up today's tree and binpkgs
- name: build and push
id: build
if: inputs.date == '' && (inputs.force || steps.existing.outputs.exists != 'true')
uses: docker/build-push-action@v7
with:
context: .github/autobump-env
build-args: BASE=${{ steps.image.outputs.base }}
push: true
no-cache: true
# no attestation manifests: the cleanup below deletes untagged versions
provenance: false
tags: ${{ steps.image.outputs.ref }}
# rebuilding a day leaves the version it replaced untagged, taking a slot below
- name: drop replaced images
uses: actions/delete-package-versions@v5
with:
owner: ${{ github.repository_owner }}
package-name: autobump-env
package-type: container
delete-only-untagged-versions: true
min-versions-to-keep: 0
# keep three days, the range env_date can fall back to
- name: drop superseded images
if: steps.build.outcome == 'success'
uses: actions/delete-package-versions@v5
with:
owner: ${{ github.repository_owner }}
package-name: autobump-env
package-type: container
min-versions-to-keep: 3