fix(ci): merge should only use digests of the same scheme #148
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Image | |
on: | |
push: | |
pull_request: | |
schedule: | |
- cron: "0 0 1 * *" | |
workflow_dispatch: | |
inputs: | |
deploy: | |
type: boolean | |
description: Whether to deploy the build images | |
jobs: | |
build: | |
if: "!(github.event_name == 'push' && contains(github.event.head_commit.message, '[skip ci]'))" | |
strategy: | |
matrix: | |
scheme: | |
- small | |
- full | |
platform: | |
- linux/amd64 | |
- linux/arm64 | |
name: Build TeXLive [${{ matrix.scheme }}-scheme,${{ matrix.platform }}] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup enviroment | |
run: | | |
platform=${{ matrix.platform }} | |
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
echo "SCHEME=${{ matrix.scheme }}" >> "$GITHUB_ENV" | |
echo "TAG=ghcr.io/xu-cheng/texlive-${{ matrix.scheme }}" >> "$GITHUB_ENV" | |
- name: Setup Git repository | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
build-args: scheme=${{ matrix.scheme }} | |
platforms: ${{ matrix.platform }} | |
load: true | |
tags: texlive-${{ matrix.scheme }} | |
- name: Test pdflatex | |
working-directory: /tmp/ | |
run: | | |
docker run --rm texlive-$SCHEME pdflatex --version | |
cat <<EOF >test.tex | |
\documentclass{article} | |
\usepackage{newtxtext} | |
\begin{document} | |
test | |
\end{document} | |
EOF | |
docker run --rm -v $(pwd):/data -w /data texlive-$SCHEME python3 /opt/texlive/bin/texliveonfly test.tex | |
file test.pdf | grep -q ' PDF ' | |
- name: Test latexindent | |
working-directory: /tmp/ | |
run: | | |
cat <<EOF >test.tex | |
\documentclass{article} | |
\usepackage{newtxtext} | |
\begin{document} | |
test | |
\end{document} | |
EOF | |
docker run --rm -v $(pwd):/data -w /data texlive-$SCHEME latexindent test.tex | |
if: "matrix.scheme == 'full'" | |
- name: Login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.CR_PAT }} | |
if: "github.ref == 'refs/heads/master'" | |
- name: Push image | |
id: push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
build-args: scheme=${{ matrix.scheme }} | |
platforms: ${{ matrix.platform }} | |
outputs: type=image,name=${{ env.TAG }},push-by-digest=true,name-canonical=true,push=true | |
if: "github.ref == 'refs/heads/master' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.deploy))" | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.push.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
if: "github.ref == 'refs/heads/master' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.deploy))" | |
- name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ matrix.scheme }}-${{ env.PLATFORM_PAIR }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
if: "github.ref == 'refs/heads/master' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.deploy))" | |
merge: | |
if: "github.ref == 'refs/heads/master' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.deploy))" | |
strategy: | |
matrix: | |
scheme: | |
- small | |
- full | |
name: Merge Image [${{ matrix.scheme }}-scheme] | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: Setup enviroment | |
run: | | |
echo "SCHEME=${{ matrix.scheme }}" >> "$GITHUB_ENV" | |
echo "TAG=ghcr.io/xu-cheng/texlive-${{ matrix.scheme }}" >> "$GITHUB_ENV" | |
echo "VERSION=$(date "+%Y%m%d")" >> "$GITHUB_ENV" | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-${{ matrix.scheme }}-* | |
merge-multiple: true | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.CR_PAT }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create --tag "$TAG:$VERSION" $(printf "$TAG@sha256:%s " *) | |
docker buildx imagetools create --tag "$TAG:latest" $(printf "$TAG@sha256:%s " *) | |
- name: Inspect images | |
run: | | |
docker buildx imagetools inspect "$TAG:$VERSION" | |
docker buildx imagetools inspect "$TAG:latest" | |