From c73790534c016d4d5a16fa8766312580ca70f4b7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 7 Jun 2024 13:14:46 +0200 Subject: [PATCH 1/2] init-g4w-for-pacman: DRY up the cache key definition The custom `init-g4w-for-pacman` Action initializes a subset of Git for Windows' SDK via a specific sparse checkout. To make things a bit more efficient, this sparse checkout is cached using the `actions/cache` Action. To that end, a cache key is defined. It is actually defined twice, once in the `restore` step and once in the `save` step. This leaves room to forget updating the cache key in one of the two places when it is changed. Let's just define it in a single location instead. Signed-off-by: Johannes Schindelin --- .github/actions/init-g4w-sdk-for-pacman/action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/actions/init-g4w-sdk-for-pacman/action.yml b/.github/actions/init-g4w-sdk-for-pacman/action.yml index 92dc692d..96b49a57 100644 --- a/.github/actions/init-g4w-sdk-for-pacman/action.yml +++ b/.github/actions/init-g4w-sdk-for-pacman/action.yml @@ -13,7 +13,9 @@ runs: run: | git clone --bare --depth=1 --single-branch --branch=main --filter=blob:none \ https://github.com/git-for-windows/git-sdk-64 .tmp && - echo "rev=$(git -C .tmp rev-parse HEAD)" >>$GITHUB_OUTPUT + rev="$(git -C .tmp rev-parse HEAD)" && + echo "rev=$rev" >>$GITHUB_OUTPUT && + echo "cache-key=g4w-sdk-$rev" >>$GITHUB_OUTPUT - name: restore cached git-sdk-64 subset id: restore-g4w-sdk uses: actions/cache/restore@v4 @@ -21,7 +23,7 @@ runs: cache-name: cache-g4w-sdk with: path: .sdk - key: g4w-sdk-${{ steps.clone-g4w-sdk.outputs.rev }} + key: ${{ steps.clone-g4w-sdk.outputs.cache-key }} - name: check out git-sdk-64 subset if: ${{ steps.restore-g4w-sdk.outputs.cache-hit != 'true' }} shell: bash @@ -59,7 +61,7 @@ runs: cache-name: cache-g4w-sdk with: path: .sdk - key: g4w-sdk-${{ steps.clone-g4w-sdk.outputs.rev }} + key: ${{ steps.clone-g4w-sdk.outputs.cache-key }} - name: use git-sdk-64 subset id: use-sdk shell: bash From c63e713d3e6569ed5e678419940b7c2e72358a79 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 7 Jun 2024 13:03:49 +0200 Subject: [PATCH 2/2] updpkgsums: include all required files in the sparse checkout When the `updpkgsums` workflow runs, it initializes a subset of Git for Windows SDK's repository via a sparse checkout. This subset is defined in the custom `init-g4w-sdk-for-pacman` Action, and it works well for `pacman`/`updpkgsums` invocations. For `makepkg`, however, we need to include the Pacman configuration, and `gpg.exe`,otherwise the workflow will fail with an error message like this: ==> Checking runtime dependencies... error: config file /etc/pacman.conf could not be read: No such file or directory This happened in this failed workflow run: https://github.com/git-for-windows/git-for-windows-automation/actions/runs/9415088089/job/25935346092#step:9:87 Fix this by including the Pacman configuration and `gpg.exe in the sparse checkout. Signed-off-by: Johannes Schindelin --- .../init-g4w-sdk-for-pacman/action.yml | 44 +++++++++++++++++-- .github/workflows/updpkgsums.yml | 2 + 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/actions/init-g4w-sdk-for-pacman/action.yml b/.github/actions/init-g4w-sdk-for-pacman/action.yml index 96b49a57..8632d970 100644 --- a/.github/actions/init-g4w-sdk-for-pacman/action.yml +++ b/.github/actions/init-g4w-sdk-for-pacman/action.yml @@ -1,5 +1,10 @@ name: 'Initialize Git for Windows SDK subset to run `pacman`' description: 'This composite GitHub Action initializes a subset of the Git for Windows SDK intended to run `pacman` and friends' +inputs: + include-makepkg: + description: 'Whether to include a working `makepkg`' + required: false + default: 'false' outputs: result: description: 'The path to the subset of the SDK' @@ -15,7 +20,7 @@ runs: https://github.com/git-for-windows/git-sdk-64 .tmp && rev="$(git -C .tmp rev-parse HEAD)" && echo "rev=$rev" >>$GITHUB_OUTPUT && - echo "cache-key=g4w-sdk-$rev" >>$GITHUB_OUTPUT + echo "cache-key=g4w-sdk-$rev${{ inputs.include-makepkg != 'false' && '+makepkg' || '' }}" >>$GITHUB_OUTPUT - name: restore cached git-sdk-64 subset id: restore-g4w-sdk uses: actions/cache/restore@v4 @@ -50,10 +55,43 @@ runs: /usr/share/makepkg/ /mingw64/bin/curl.exe EOF + if test false != '${{ inputs.include-makepkg }}' + then + printf "%s\n" >>"$sparse" \ + /etc/pacman.conf \ + /etc/pacman.d/ \ + /var/lib/pacman/ \ + /usr/bin/gpg.exe && + # cheap `objdump -p | grep DLL.Name:` alternative + LC_CTYPE=C sed -n ' + # surround MSYS DLL names with `<` and `>` and avoid false positives + s|[<>]||g + s|\(msys-[-a-z0-9.]*\.dll\)|<\1>|g + + # remove everything except the MSYS DLL names + s|^[^<]*<*|| + s|>*[^>]*$|| + s|>[^<>]*<|\n|g + + # skip empty lines + /^$/d + + # prefix the MSYS DLL names with `/usr/bin/` + s|^|/usr/bin/| + s|\n|&/usr/bin/|g + + # print the result + p' /usr/bin/gpg.exe >>"$sparse" + fi && git checkout -- && - # makepkg/updpkgsums expects `curl` to be present in `/usr/bin/` - printf '#!/bin/sh\n\nexec /mingw64/bin/curl.exe "$@"' >usr/bin/curl + # makepkg/updpkgsums expect `curl` to be present in `/usr/bin/` + printf '#!/bin/sh\n\nexec /mingw64/bin/curl.exe "$@"' >usr/bin/curl && + { + # makepkg expects `git` to be present in `/usr/bin/` + test ! -x mingw64/bin/git.exe || + printf '#!/bin/sh\n\nexec /mingw64/bin/git.exe "$@"' >usr/bin/git + } - name: cache git-sdk-64 subset if: ${{ steps.restore-g4w-sdk.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 diff --git a/.github/workflows/updpkgsums.yml b/.github/workflows/updpkgsums.yml index ec2e1630..06ba70e2 100644 --- a/.github/workflows/updpkgsums.yml +++ b/.github/workflows/updpkgsums.yml @@ -63,6 +63,8 @@ jobs: core.setOutput('token', accessToken) - name: Initialize Git for Windows SDK subset uses: ./.github/actions/init-g4w-sdk-for-pacman + with: + include-makepkg: true - name: Clone ${{ env.REPO }} id: clone shell: bash