From 2fc2a433374b74131dbd3cad13c8dd4b05afef99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Mon, 27 Feb 2023 20:10:31 +0100 Subject: [PATCH] Make GH Actions less reliant on TL mirror availability --- .github/workflows/main.yaml | 29 ++++++++++++++---- .github/workflows/trigger.yaml | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/trigger.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 71fa51148..8c1c03b24 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -13,6 +13,23 @@ on: # requests get tested even if their branch comes from a fork. jobs: + # Update the TeX Live tree if necessary + texlive-cache: + runs-on: ubuntu-20.04 + name: Update TeX Live + outputs: + cache_key: ${{ steps.texlive.outputs.cache_key }} + steps: + # Boilerplate + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install TeX Live + id: texlive + uses: zauguin/install-texlive@v3 + with: + # List the required TeX Live packages in a separate file to allow reuse in + # different workflows. + package_file: .github/tl_packages # The l3build job contains the actual work. We misuse the matrix mechanism to # create three jobs which only differ in minimal elements. # For tags we do not run this since we run the release job instead. @@ -72,18 +89,20 @@ jobs: l3build_cmd: cd required && l3build doc -q -H --show-log-on-error artifact_name: Documentation name: ${{ matrix.name }} + needs: texlive-cache steps: # Boilerplate - name: Checkout repository uses: actions/checkout@v3 # We need Ghostscript for dvips and XeTeX tests. - run: sudo apt-get update && sudo apt-get install ghostscript - - name: Install TeX Live - uses: zauguin/install-texlive@v2 + - name: Restore TeX Live from cache + uses: actions/cache/restore@v3 with: - # List the required TeX Live packages in a separate file to allow reuse in - # different workflows. - package_file: .github/tl_packages + path: ~/texlive + key: ${{ needs.texlive-cache.outputs.cache_key }} + fail-on-cache-miss: true + - run: echo $HOME/texlive/bin/x86_64-linux >> $GITHUB_PATH - name: Run l3build run: ${{ matrix.l3build_cmd }} # Now we create the artifacts: There are two cases where this happens. diff --git a/.github/workflows/trigger.yaml b/.github/workflows/trigger.yaml new file mode 100644 index 000000000..f0db4fe00 --- /dev/null +++ b/.github/workflows/trigger.yaml @@ -0,0 +1,55 @@ +name: Manually refresh caches + +on: + workflow_dispatch: + inputs: + repository: + default: ctan + description: 'Repository URL' + required: false + type: string + delete-old: + default: false + description: 'Delete all caches' + required: false + type: boolean + +jobs: + rebuild-cache: + runs-on: ubuntu-latest + permissions: + actions: write + contents: read + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Clean old caches + run: | + gh extension install actions/gh-actions-cache + + REPO="${{ github.repository }}" + BRANCH="${{ github.ref }}" + HASH_KEY="texlive-0-${{ hashFiles(".github/tl_packages") }}-" + DATE="$(date -I)" + + if ${{ inputs.delete-old }} + then + HASH_KEY="$HASH_KEY-$DATE" + fi + set +e + gh actions-cache list -R "$REPO" -B "$BRANCH" --key "$HASH_KEY" | cut -f 1 | while read -r cacheKey + do + gh actions-cache delete "$cacheKey" -R "$REPO" -B "$BRANCH" --confirm + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install TeX Live + id: texlive + uses: zauguin/install-texlive@v3 + with: + # List the required TeX Live packages in a separate file to allow reuse in + # different workflows. + accept-stale: false + repository: ${{ inputs.repository }} + package_file: .github/tl_packages