diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml new file mode 100644 index 0000000..7977299 --- /dev/null +++ b/.github/actionlint.yaml @@ -0,0 +1,6 @@ +# actionlint doesn't yet understand the `$/` self-repository `uses:` syntax. +# See https://github.com/rhysd/actionlint/issues/711. +paths: + .github/workflows/**: + ignore: + - 'reusable workflow call "\$/[^"]*" at "uses" is not following the format "owner/repo/path/to/workflow.yml@ref" nor "./path/to/workflow.yml"' diff --git a/.github/workflows/close-actions.yml b/.github/workflows/close-actions.yml index 81c5439..2f64f83 100644 --- a/.github/workflows/close-actions.yml +++ b/.github/workflows/close-actions.yml @@ -17,12 +17,9 @@ jobs: cleanup: name: Cleanup from previous test runs if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Delete previous test release - env: - GH_TOKEN: ${{ github.token }} - run: gh release delete vtest-${{ github.ref_name }} --cleanup-tag -y || echo "No previous release to delete" + uses: $/.github/workflows/workflow-cleanup-test-release.yml + permissions: + contents: write + with: + pr-number: ${{ github.event.pull_request.number }} + ref-name: ${{ github.event.pull_request.head.ref }} diff --git a/.github/workflows/test-app-workflow.yml b/.github/workflows/test-app-workflow.yml index 9e10d8f..49bdf26 100644 --- a/.github/workflows/test-app-workflow.yml +++ b/.github/workflows/test-app-workflow.yml @@ -23,18 +23,14 @@ permissions: jobs: cleanup: name: Cleanup from previous test runs - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Delete previous test release - env: - GH_TOKEN: ${{ github.token }} - run: gh release delete vtest-${{ github.ref_name }} --cleanup-tag -y || echo "No previous release to delete" + uses: $/.github/workflows/workflow-cleanup-test-release.yml + permissions: + contents: write + with: + ref-name: ${{ github.ref_name }} test: - uses: ./.github/workflows/workflow-build.yml + uses: $/.github/workflows/workflow-build.yml with: app-name: "test_app" build-type: ${{ github.event.inputs['build-type'] || 'release' }} diff --git a/.github/workflows/workflow-cleanup-test-release.yml b/.github/workflows/workflow-cleanup-test-release.yml new file mode 100644 index 0000000..621e91d --- /dev/null +++ b/.github/workflows/workflow-cleanup-test-release.yml @@ -0,0 +1,69 @@ +name: Cleanup Test Release + +on: + workflow_call: + inputs: + ref-name: + description: "The ref name to clean up (e.g. main or 89/merge)" + required: false + type: string + default: "" + pr-number: + description: "The pull request number to clean up" + required: false + type: number + +permissions: + contents: write + +jobs: + cleanup: + name: Cleanup test releases + runs-on: ubuntu-latest + steps: + - name: Delete test releases + env: + GH_TOKEN: ${{ github.token }} + INPUT_REF_NAME: ${{ inputs['ref-name'] }} + INPUT_PR_NUMBER: ${{ inputs['pr-number'] }} + GITHUB_REF_NAME: ${{ github.ref_name }} + REPO: ${{ github.repository }} + run: | + echo "INPUT_REF_NAME='$INPUT_REF_NAME'" + echo "INPUT_PR_NUMBER='$INPUT_PR_NUMBER'" + echo "GITHUB_REF_NAME='$GITHUB_REF_NAME'" + echo "REPO='$REPO'" + + TARGETS=() + + if [ -n "$INPUT_REF_NAME" ]; then + TARGETS+=("vtest-$INPUT_REF_NAME") + fi + + if [[ "$INPUT_PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then + TARGETS+=("vtest-$INPUT_PR_NUMBER/merge") + fi + + if [ ${#TARGETS[@]} -eq 0 ]; then + TARGETS+=("vtest-$GITHUB_REF_NAME") + fi + + echo "Resolved TARGETS=(${TARGETS[*]})" + + for target in "${TARGETS[@]}"; do + echo "Searching releases for target: $target..." + export TARGET="$target" + RELEASE_IDS=$(gh api --paginate "repos/$REPO/releases?per_page=100" \ + --jq '.[] | select(.tag_name == env.TARGET or .name == ("🔖 " + env.TARGET)) | .id') + + if [ -n "$RELEASE_IDS" ]; then + echo "Found release ID(s) for $target: $RELEASE_IDS" + for id in $RELEASE_IDS; do + echo "Deleting release $id ($target)..." + gh api -X DELETE "repos/$REPO/releases/$id" + echo "Successfully deleted release $id" + done + else + echo "No previous release found for $target" + fi + done