generated from kachick/anylang-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement staging container action (#53)
* Implement staging container action Import kachick/dotfiles#473 and following commits in that repo
- Loading branch information
Showing
2 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: 👋 staging ⬢🗑️ | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
workflow_dispatch: | ||
inputs: | ||
pr-number: | ||
description: 'Target PR number' | ||
required: true | ||
type: number | ||
|
||
defaults: | ||
run: | ||
# https://pubs.opengroup.org/onlinepubs/009695399/utilities/set.html | ||
shell: bash -Ceuxo pipefail {0} | ||
|
||
jobs: | ||
ghcr: | ||
runs-on: ubuntu-22.04 | ||
if: (github.event_name != 'pull_request') || (github.event.pull_request.merged == true) | ||
timeout-minutes: 15 | ||
steps: | ||
- name: Install gh-action-escape | ||
run: curl -fsSL https://raw.githubusercontent.com/kachick/gh-action-escape/main/scripts/install-in-github-action.sh | sh -s v0.2.0 | ||
- name: Get metadata | ||
id: get-meta | ||
run: | | ||
if [ '${{ github.event_name }}' == 'pull_request' ]; then | ||
echo -n '${{ github.event.pull_request.number }}' | gh-action-escape -name=pr_number | tee -a "$GITHUB_OUTPUT" | ||
else | ||
echo -n '${{ inputs.pr-number }}' | gh-action-escape -name=pr_number | tee -a "$GITHUB_OUTPUT" | ||
fi | ||
- name: Inspect the PR published package | ||
id: inspect-package | ||
run: | | ||
gh api --paginate \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
/users/kachick/packages/container/ubuntu-nix-systemd/versions \ | ||
--jq '.[] | select(.metadata.container.tags[] | match("^pr-${{ steps.get-meta.outputs.pr_number }}-")).id' | \ | ||
ruby -e 'puts STDIN.each_line.map(&:chomp).join(",")' | \ | ||
gh-action-escape -name=ubuntu-nix-systemd-package-version-ids | tee -a "$GITHUB_OUTPUT" | ||
gh api --paginate \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
/users/kachick/packages/container/ubuntu-nix-sudoer/versions \ | ||
--jq '.[] | select(.metadata.container.tags[] | match("^pr-${{ steps.get-meta.outputs.pr_number }}-")).id' | \ | ||
ruby -e 'puts STDIN.each_line.map(&:chomp).join(",")' | \ | ||
gh-action-escape -name=ubuntu-nix-sudoer-package-version-ids | tee -a "$GITHUB_OUTPUT" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0 | ||
with: | ||
owner: ${{ github.repository_owner }} | ||
package-name: 'ubuntu-nix-systemd' | ||
package-type: 'container' | ||
token: ${{ github.token }} | ||
package-version-ids: ${{ steps.inspect-package.outputs.ubuntu-nix-systemd-package-version-ids }} | ||
- uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0 | ||
with: | ||
owner: ${{ github.repository_owner }} | ||
package-name: 'ubuntu-nix-sudoer' | ||
package-type: 'container' | ||
token: ${{ github.token }} | ||
package-version-ids: ${{ steps.inspect-package.outputs.ubuntu-nix-sudoer-package-version-ids }} | ||
- name: Prepare git to run gh commands | ||
uses: actions/checkout@v4 | ||
- name: Post comments to the PR | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
( | ||
cat <<'EOF' | ||
🤖 removed 🗑️ staging ⬢ from ghcr.io | ||
```plaintext | ||
${{ steps.inspect-package.outputs.ubuntu-nix-systemd-package-version-ids }} | ||
${{ steps.inspect-package.outputs.ubuntu-nix-sudoer-package-version-ids }} | ||
``` | ||
EOF | ||
) | gh pr comment '${{ steps.get-meta.outputs.pr_number }}' --body-file - |
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