JQ_QUERY #28
Workflow file for this run
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: Gorelease | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
commit: | |
type: string | |
description: Checkout the specified commit | |
delete: | |
type: boolean | |
description: Trigger delete workflow | |
registry: | |
type: choice | |
description: Select the container registry | |
options: | |
- ghcr.io | |
- dockerhub | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
release: | |
if: "${{ !github.event.inputs.delete }}" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Checkout code at the specific commit | |
if: "${{ github.event.inputs.commit != '' }}" | |
run: git checkout ${{ github.event.inputs.commit }} | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
- name: "Read secrets" | |
uses: rancher-eio/read-vault-secrets@main | |
if: "${{ github.event.inputs.registry == 'dockerhub' }}" | |
with: | |
secrets: | | |
secret/data/github/repo/${{ github.repository }}/dockerhub/${{ github.repository_owner }}/credentials username | DOCKER_USERNAME ; | |
secret/data/github/repo/${{ github.repository }}/dockerhub/${{ github.repository_owner }}/credentials password | DOCKER_PASSWORD ; | |
- name: Login to Docker Container Registry | |
uses: docker/login-action@v3 | |
if: "${{ github.event.inputs.registry == 'dockerhub' }}" | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
# trigger login also for push | |
if: "${{ github.event.inputs.registry != 'dockerhub' }}" | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create fake tag | |
id: fake-tag | |
run: | | |
CURRENT_TAG=$(git describe --tag --always) | |
git tag ${CURRENT_TAG} | |
echo "CURRENT_TAG=${CURRENT_TAG}" >> "$GITHUB_OUTPUT" | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser | |
version: v2 | |
args: --clean | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GORELEASER_CURRENT_TAG: ${{ steps.fake-tag.outputs.CURRENT_TAG }} | |
release-deleted: | |
if: "${{ github.event.inputs.delete }}" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Checkout code at the specific commit | |
if: "${{ github.event.inputs.commit != '' }}" | |
run: git checkout ${{ github.event.inputs.commit }} | |
- name: Deleting | |
run: | | |
CURRENT_TAG=$(git describe --tag --always) | |
echo "Deleting packages with tag ${CURRENT_TAG}" | |
JQ_QUERY=".[] | select(.metadata.container.tags[] == \"${CURRENT_TAG}\" or .metadata.container.tags[] == \"${CURRENT_TAG}-kubelet\")" | |
echo "JQ_QUERY ${JQ_QUERY}" | |
PACKAGES_TO_DELETE=$(gh api /user/packages/container/k3k/versions --jq ${JQ_QUERY}) | |
echo $PACKAGES_TO_DELETE | jq |