Skip to content

Tag latest

Tag latest #9763

Workflow file for this run

name: Tag latest
on:
push:
branches:
- "main"
paths:
- "tools/**"
- ".github/workflows/tag.yml"
- ".github/workflows/trigger-pages.yml"
schedule:
- cron: "18 * * * *"
workflow_run:
workflows:
- Automerge
types:
- completed
workflow_dispatch:
inputs:
tools:
description: 'Tools to build/promote'
type: string
default: ''
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
collect:
name: Collect changed tools
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-22.04
outputs:
tools: ${{ steps.collect.outputs.tools }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient
- name: Collect
id: collect
run: |
CHANGED_TOOLS="${{ inputs.tools }}"
if test -z "${CHANGED_TOOLS}"; then
echo "### Fetching config for metadata"
OLD_COMMIT_SHA="$(
helper/usr/local/bin/regctl manifest get ghcr.io/uniget-org/tools/metadata:main --format raw-body \
| helper/usr/local/bin/jq --raw-output '.layers[0].digest' \
| xargs -I{} \
helper/usr/local/bin/regctl blob get ghcr.io/uniget-org/tools/metadata:main {} \
| tar --extract --gzip --to-stdout \
| helper/usr/local/bin/jq --raw-output '.revision'
)"
echo "### Fetching changed tools for ${OLD_COMMIT_SHA}..${GITHUB_SHA}"
CHANGED_TOOLS="$(
git log --pretty=format: --name-only --diff-filter=d ${OLD_COMMIT_SHA}..${GITHUB_SHA} \
| sort \
| grep -E "^tools/[^/]+/" \
| cut -d/ -f2 \
| uniq \
| while read -r TOOL; do test -d "tools/${TOOL}" && echo "${TOOL}"; done \
| xargs
)"
fi
echo "### Tools to process: ${CHANGED_TOOLS}."
CHANGED_TOOLS_JSON="$(
echo -n "${CHANGED_TOOLS}" \
| tr ' ' '\n' \
| helper/usr/local/bin/jq --raw-input '.' | jq --slurp --compact-output '.'
)"
echo " JSON: ${CHANGED_TOOLS_JSON}"
echo "tools=${CHANGED_TOOLS_JSON}" >>"${GITHUB_OUTPUT}"
collect_versions:
name: Collect versions for tools
needs:
- collect
if: ${{ needs.collect.outputs.tools != '[]' && needs.collect.outputs.tools != '' }}
runs-on: ubuntu-22.04
outputs:
tools_with_version: ${{ steps.extract_versions.outputs.tools_with_version }}
env:
tools: ${{ needs.collect.outputs.tools }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: yq gojq
- name: Extract versions
id: extract_versions
run: |
echo "Processing tools: ${tools}."
tools_with_version=""
TOOLS_RAW="$(
echo "${tools}" \
| helper/usr/local/bin/jq --raw-output '.[]'
)"
for TOOL in ${TOOLS_RAW}; do
echo "${TOOL}"
VERSION="$( helper/usr/local/bin/yq '.version' "tools/${TOOL}/manifest.yaml" )"
echo "${VERSION}"
tools_with_version="${tools_with_version}${TOOL}:${VERSION} "
done
echo "tools_with_version=${tools_with_version}."
tools_with_version_json="$(
echo -n "${tools_with_version}" \
| tr ' ' '\n' \
| helper/usr/local/bin/jq --raw-input '.' \
| helper/usr/local/bin/jq --slurp --compact-output '.'
)"
echo "JSON: ${tools_with_version_json}"
echo "tools_with_version=${tools_with_version_json}" >>"${GITHUB_OUTPUT}"
tag:
name: Tag latest
permissions:
contents: read
packages: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: ubuntu-22.04
needs:
- collect
if: ${{ needs.collect.outputs.tools != '[]' && needs.collect.outputs.tools != '' }}
strategy:
fail-fast: false
matrix:
tool: ${{ fromJSON(needs.collect.outputs.tools) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient yq
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: uniget-bot
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag latest
run: |
echo "### Processing ${{ matrix.tool }}"
tool_version="$( helper/usr/local/bin/yq eval .version tools/${{ matrix.tool }}/manifest.yaml )"
version_tag="$( echo "${tool_version}" | tr '+' '-' )"
rebuild=false
if ! latest_sha="$( helper/usr/local/bin/regctl manifest head ghcr.io/uniget-org/tools/${{ matrix.tool }}:latest )"; then
echo "No latest tag found"
fi
echo "Got latest tag: ${latest_sha}."
if ! version_sha="$( helper/usr/local/bin/regctl manifest head ghcr.io/uniget-org/tools/${{ matrix.tool }}:${version_tag} )"; then
echo "No version tag found"
rebuild=true
fi
echo "Got version tag: ${version_sha}."
if ! ${rebuild} && test -n "${latest_sha}" && test "${latest_sha}" == "${version_sha}"; then
echo "Latest tag is equal to version tag"
rebuild=true
fi
echo "Rebuild: ${rebuild}."
if ${rebuild}; then
echo "### Building ${{ matrix.tool }}"
make "${{ matrix.tool }}--push"
fi
echo "### Promoting ${{ matrix.tool }}"
make "${{ matrix.tool }}--promote"
- name: Store logs
uses: actions/upload-artifact@v3
if: always()
with:
name: logs.zip
path: "**/build.log"
scan:
name: Scan container images
if: ${{ needs.collect_versions.outputs.tools_with_version != '[]' && needs.collect_versions.outputs.tools_with_version != '' }}
needs:
- collect_versions
- tag
permissions:
security-events: write
pull-requests: write
packages: read
strategy:
fail-fast: false
matrix:
tool_with_version: ${{ fromJSON(needs.collect_versions.outputs.tools_with_version) }}
uses: ./.github/workflows/scan.yml
with:
name_and_version: ${{ matrix.tool_with_version }}
secrets:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
metadata:
name: Metadata
permissions:
packages: write
runs-on: ubuntu-22.04
needs:
- tag
#- scan
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient yq
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: uniget-bot
password: ${{ secrets.GITHUB_TOKEN }}
- name: Update metadata
run: |
make metadata.json--push
pages:
name: tools.uniget.dev
needs:
- metadata
uses: ./.github/workflows/trigger-pages.yml
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}