β Ignore README.md from PR workflow trigger (#16) #264
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: Docker | |
on: | |
schedule: | |
- cron: '0 3 * * *' | |
workflow_dispatch: | |
pull_request: | |
paths-ignore: [ 'README.md' ] | |
push: | |
branches: [ 'master' ] | |
tags: [ 'v*' ] | |
env: | |
BUILDKIT_PROGRESS: plain | |
GHCR: ghcr.io | |
REGISTRY: ${{ vars.REGISTRY }} | |
IMAGE_NAME: ${{ vars.IMAGE_NAME }} | |
REPO: ${{ vars.REPO }} | |
PUSH_IMAGE: ${{ github.event_name != 'pull_request' }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write # See https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id | |
contents: read | |
packages: write | |
steps: | |
# Checkout the repository | |
- name: Checkout π― | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
# Get current year | |
- name: Get current year π | |
id: get-year | |
shell: bash | |
run: echo "year=$(date +%Y)" >> ${GITHUB_OUTPUT} | |
# Restore cached repository | |
# https://github.com/actions/cache/tree/main/restore | |
- name: Restore cached repository π¦ | |
id: restore | |
uses: actions/cache/restore@v3 | |
with: | |
path: texlive/ | |
key: rsync-TL${{ steps.get-year.outputs.year }}-${{ github.sha }} | |
restore-keys: | | |
rsync-TL${{ steps.get-year.outputs.year }}- | |
rsync- | |
enableCrossOsArchive: true | |
fail-on-cache-miss: false | |
- name: Run rsync π | |
shell: bash | |
run: | | |
echo "::group::rsync" | |
script/rsync.sh ${{ env.REPO }} texlive/ --exclude-from=rsyncignore.txt | |
echo "::endgroup::" | |
echo "::group::Repository tree" | |
tree -nh texlive/ | |
echo "::endgroup::" | |
# Get the release version of the repository | |
- name: Get TeX Live release version π | |
id: tl-release | |
shell: bash | |
run: echo "number=$(find ${{ github.workspace }}/texlive/ -name 'TEXLIVE_*' -print0 | sed -e s/[^0-9]//g)" >> ${GITHUB_OUTPUT} | |
# Save repository to cache | |
# https://github.com/actions/cache/tree/main/save | |
- name: Save repository to cache πΎ | |
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }} | |
uses: actions/cache/save@v3 | |
with: | |
path: texlive/ | |
key: rsync-TL${{ steps.tl-release.outputs.number }}-${{ github.sha }} | |
enableCrossOsArchive: true | |
# Workaround: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy | |
- name: Delete old repo cache ποΈ | |
if: ${{ steps.restore.outputs.cache-hit }} | |
shell: bash | |
run: | | |
gh extension install actions/gh-actions-cache | |
[ $(gh actions-cache list -R ${{ github.repository }} -B ${{ github.ref }} --key rsync- | wc -l) -lt 2 ] && exit 0 | |
gh actions-cache delete ${{ steps.restore.outputs.cache-matched-key }} -R ${{ github.repository }} --confirm | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Add support for more platforms with QEMU | |
# https://github.com/docker/setup-qemu-action | |
- name: Set up QEMU π» | |
uses: docker/setup-qemu-action@v2 | |
# Add support for Buildx | |
# https://github.com/docker/setup-buildx-action | |
- name: Setup buildx π§ | |
uses: docker/setup-buildx-action@v2 | |
# Extract metadata (tags, labels) | |
# https://github.com/docker/metadata-action | |
- name: Extract metadata π | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.GHCR }}/${{ github.repository }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
bake-target: metadata-action-bullseye-full | |
flavor: | | |
latest=auto | |
prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,onlatest=false | |
tags: | | |
type=schedule,pattern=nightly | |
type=semver,pattern=v{{version}} | |
type=semver,pattern=v{{major}}.{{minor}} | |
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} | |
type=sha,prefix=TL${{ steps.tl-release.outputs.number }}-bullseye-full-,format=short | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
# Read platforms as CSV from bake file | |
- name: Read platforms from bake file π | |
id: get-platforms | |
shell: bash | |
run: echo "platform=$(docker buildx bake -f docker-bake.hcl --print _platforms | jq -cr '.target._platforms.platforms | @csv' | tr -d '"')" >> ${GITHUB_OUTPUT} | |
# Login to GitHub registry | |
# https://github.com/docker/login-action | |
- name: Log into GitHub registry π | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.GHCR }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Login to another registry | |
# https://github.com/docker/login-action | |
- name: Log into ${{ env.REGISTRY }} π | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
# Free up disk space | |
# Workaround: actions/runner-images#2840 | |
- name: Free up disk space ποΈ | |
# Since this step is not critical as long as the space is freed up, we can ignore errors | |
continue-on-error: true | |
shell: bash | |
run: | | |
echo "::group::Current disk space usage" | |
echo "Listing 100 largest packages" | |
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100 | |
df -h | |
echo "::endgroup::" | |
echo "::group::Purging apt packages" | |
echo "Removing large packages" | |
sudo apt purge -qy \ | |
'^dotnet-.*' '^mono.*' \ | |
'^llvm-.*' '^libllvm.*' '^clang-.*' '^libclang.*' \ | |
'^gfortran-.*' \ | |
'^mysql.*' '^postgresql.*' '^mongodb.*' | |
sudo apt purge -qy \ | |
azure-cli \ | |
microsoft-edge-stable \ | |
google-chrome-stable \ | |
firefox \ | |
powershell \ | |
nginx \ | |
libgl1-mesa-dri | |
sudo apt autoremove -qy | |
sudo apt clean -qy | |
df -h | |
echo "::endgroup::" | |
echo "Removing large directories..." | |
sudo rm -rf \ | |
${AGENT_TOOLSDIRECTORY} \ | |
/usr/share/dotnet \ | |
/usr/local/graalvm/ \ | |
/usr/local/.ghcup/ \ | |
/usr/local/lib/android \ | |
/usr/local/lib/node_modules \ | |
/usr/local/share/chromium \ | |
/usr/local/share/edge_driver \ | |
/usr/local/share/powershell \ | |
/usr/local/share/vcpkg | |
df -h | |
docker system df | |
# Build Docker image with Bake | |
# https://github.com/docker/bake-action | |
- name: Build / Push image π³ | |
uses: docker/bake-action@v2 | |
with: | |
files: | | |
docker-bake.hcl | |
${{ steps.meta.outputs.bake-file }} | |
set: | | |
*.cache-to=type=registry,mode=max,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache,oci-mediatypes=true | |
*.cache-from=type=registry,ref=${{ env.GHCR }}/${{ github.repository }}:buildcache | |
*.platform=${{ steps.get-platforms.outputs.platform }} | |
env: | |
PUSH: ${{ fromJson(env.PUSH_IMAGE) }} | |
# Cleanup repository | |
- name: Cleanup π§Ή | |
if: ${{ ! fromJson(env.PUSH_IMAGE) }} | |
shell: bash | |
run: | | |
echo "::group::Current disk" | |
df -h | |
tree -nhL 2 | |
echo "::endgroup::" | |
rm -rf texlive | |
df -h | |
# Upload artifacts | |
# https://github.com/actions/upload-artifact | |
- name: Upload artifacts π | |
if: ${{ ! fromJson(env.PUSH_IMAGE) }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: TL${{ steps.tl-release.outputs.number }} | |
path: texlive.oci | |
if-no-files-found: error |