fixup! Add a GitHub workflow to uninstall packages from the SDKs #5
This file contains hidden or 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: Drop Pacman package from SDKs | |
on: | |
push: | |
env: | |
PACKAGE: git-flow | |
COMMIT_MESSAGE: The Git Flow package is obsolete and unmaintained. It is no longer distributed with Git for Windows, see https://github.com/git-for-windows/build-extra/pull/648 for details. | |
GIT_CONFIG_PARAMETERS: "'user.name=Git for Windows Build Agent' '[email protected]' 'windows.sdk64.path=${{ github.workspace }}' 'windows.sdk32.path=' 'http.sslbackend=schannel' 'core.autocrlf=false' 'checkout.workers=56'" | |
HOME: "${{ github.workspace }}\\home\\git-ci" | |
MSYSTEM: MSYS | |
jobs: | |
drop-pacman-package: | |
strategy: | |
matrix: | |
sdk: [git-sdk-arm64] | |
runs-on: ${{ matrix.sdk == 'git-sdk-arm64' && 'windows-11-arm' || 'windows-latest' }} | |
steps: | |
- name: obtain installation access token | |
uses: actions/create-github-app-token@v2 | |
id: sdk-repo-token | |
with: | |
app-id: ${{ secrets.GH_APP_ID }} | |
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner }} | |
repositories: ${{ matrix.sdk }} | |
- name: clone ${{ matrix.sdk }} | |
uses: actions/checkout@v5 | |
with: | |
persist-credentials: true | |
repository: ${{ github.repository_owner }}/${{ matrix.sdk }} | |
token: ${{ steps.sdk-repo-token.outputs.token }} | |
- name: use the SDK's Bash and git.exe | |
run: "usr\\bin\\bash.exe -lc 'cygpath -aw /usr/bin >>$GITHUB_PATH && cygpath -aw /cmd >>$GITHUB_PATH'" | |
- name: Run tmate | |
shell: bash | |
run: | | |
# install tmate | |
pacman -Sy --noconfirm tmate openssh && | |
# Let Git ignore tmate's files | |
git -C / ls-files --exclude-standard --other | | |
sed 's/^/\//' >>"$(git rev-parse --git-path info/exclude)" && | |
# restrict SSH access to the "actor", i.e. the GitHub user who triggered this workflow | |
# this requires calling `ssh -i <private-key> [...]` later on | |
mkdir -p ~/.ssh && | |
curl https://api.github.com/users/${{github.actor}}/keys | jq -r '.[].key' >~/.ssh/authorized_keys && | |
# Generate an SSH key (needed for tmate) | |
echo -e 'y\n' | ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa && | |
# Start tmate session | |
export CHERE_INVOKING=1 && | |
tmate -S /tmp/tmate.sock -a ~/.ssh/authorized_keys new-session -d && | |
tmate -S /tmp/tmate.sock wait tmate-ready && | |
# Print SSH invocation | |
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}' | |
- name: Remove ${{ env.PACKAGE }} | |
shell: bash | |
run: | | |
set -x && | |
. /etc/profile && | |
# Log the output also to a file so that it can be inserted into the commit message later | |
cygpath -aw /tmp/commit-message.txt && | |
(pacman -Rns --noconfirm $PACKAGE 2>&1; echo $? >/tmp/exit.status) | | |
tee -a /tmp/commit-message.txt && | |
exit $(cat /tmp/exit.status) | |
- name: commit & open PR | |
shell: bash | |
run: | | |
set -x && | |
branch="drop-$PACKAGE-$(date +%s)" && | |
git checkout -b "$branch" && | |
git add -A . && | |
if git diff --cached --quiet; then | |
echo "::warning::${{ matrix.sdk }}: no changes to commit!" | |
exit 0 | |
fi && | |
commit_message="Drop package '$PACKAGE' | |
$COMMIT_MESSAGE | |
$(cat /tmp/commit-message.txt)" && | |
git -c core.quotepath=false -c log.showSignature=false commit -m "$commit_message" && | |
( | |
gh pr create \ | |
--title "Drop package '$PACKAGE'" \ | |
--body "$commit_message" \ | |
--head "$branch" \ | |
--base main; | |
echo $? >/tmp/exit.status | |
) | | |
tee -a /tmp/pr-create-output.txt && | |
test 0 = $(cat /tmp/exit.status) && | |
sed -n 's/.*\(http[^ ]*\).*/::notice::Opened PR \1/p' /tmp/pr-create-output.txt && | |
- name: wait for tmate to be done | |
if: always() | |
shell: bash | |
run: | | |
PATH=$HOME/bin:$PATH | |
while test -e /tmp/tmate.sock | |
do | |
tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}' | |
sleep 5 | |
done |