adding output to the clean job in rc-prep workflow #2
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: "Chart - Prepare - Release - Candidate" | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
releaseCandidateBranchName: | ||
description: "Branch Name of The Release Candidate" | ||
required: false | ||
default: "release-candidate" | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
jobs: | ||
clean: | ||
name: Clean RC artifacts | ||
permissions: | ||
packages: write | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: /tmp | ||
steps: | ||
- name: Delete old artifacts | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Get IDs of the artifacts that include "rc" (the sha256 digest). | ||
artifacts_ids_to_delete="$( | ||
gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' \ | ||
'/orgs/camunda/packages/container/helm%2Fcamunda-platform/versions?per_page=100' | \ | ||
jq '.[] | select(.metadata.container.tags[] | contains("rc")) | .id' | ||
)" | ||
# Early exit if no artifacts to delete. | ||
test -z "${artifacts_ids_to_delete}" && { | ||
echo "No RC artifacts to delete ..."; | ||
exit 0; | ||
} | ||
# Delete the RC artifacts. | ||
echo -e "Deleting the old untagged artifacts IDs:\n${artifacts_ids_to_delete}" | ||
for container_id in ${artifacts_ids_to_delete}; do | ||
gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"/orgs/camunda/packages/container/helm%2Fcamunda-platform/versions/${container_id}" | ||
done | ||
outputs: | ||
should-run: ${{ steps.conditions.outputs.should-run }} | ||
reset: | ||
needs: [clean] | ||
if: needs.clean.outputs.should-run == 'true' | ||
name: reset release-candidate branch | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Generate GitHub token | ||
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2 | ||
id: generate-github-token | ||
with: | ||
app_id: ${{ secrets.GH_APP_ID_DISTRO_CI }} | ||
private_key: ${{ secrets.GH_APP_PRIVATE_KEY_DISTRO_CI }} | ||
- name: Checkout | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | ||
with: | ||
ref: ${{ github.event.inputs.releaseCandidateBranchName }} | ||
fetch-depth: 0 | ||
token: "${{ steps.generate-github-token.outputs.token }}" | ||
- name: Reset release-candidate branch to master | ||
env: | ||
RC_BRANCH: ${{ github.event.inputs.releaseCandidateBranchName }} | ||
run: | | ||
git checkout ${{ env.RC_BRANCH }} | ||
git reset origin/main --hard |