diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index 86482cd..b80ac29 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -32,6 +32,20 @@ runs: reaction-type: "eyes" allow-edits: "false" permission-level: write + + - name: Get valid revisions for promotion + id: valid-revisions + uses: actions/github-script@v7 + with: + result-encoding: string + script: | + const issue = await github.rest.issues.get({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }) + + return issue.data.body.match(/\/promote ([0-9,]+)/)[1].split(",").join(" ") - name: Install snapcraft shell: bash @@ -65,20 +79,6 @@ runs: echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" - - name: Get valid revisions for promotion - id: valid-revisions - uses: actions/github-script@v7 - with: - result-encoding: string - script: | - const { body } = github.rest.issues.get({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - }) - - return body.match(/\/promote ([0-9,]+)/)[1].split(",").join(" ") - - name: Promote snap to latest/stable id: promote env: @@ -114,20 +114,24 @@ runs: # Iterate over each specified revision and release revs=$(echo "$revision" | tr "," "\n") released_revs=() + rejected_revs=() for r in $revs; do if [[ "$valid_revisions" =~ (^|[[:space:]])"$r"($|[[:space:]]) ]]; then snapcraft release "$snap_name" "$r" "$channel" released_revs+=("$r") else + rejected_revs+=("$r") echo "Not promoting revision '$r' because the revision is not related to this test." fi done # Get a comma separated list of released revisions printf -v joined '%s,' "${released_revs[@]}" + printf -v joined_rejected '%s,' "${rejected_revs[@]}" echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT" + echo "rejected=${joined_rejected%,}" >> "$GITHUB_OUTPUT" echo "channel=$channel" >> "$GITHUB_OUTPUT" echo "done=$done" >> "$GITHUB_OUTPUT" @@ -135,11 +139,20 @@ runs: uses: actions/github-script@v7 with: script: | + let message = "" + if ("${{ steps.promote.outputs.revisions }}".length > 0) { + message += 'The following revisions were released to the `${{ steps.promote.outputs.channel }}` channel: `${{ steps.promote.outputs.revisions }}`. ' + } + + if ("${{ steps.promote.outputs.rejected }}".length > 0) { + message += 'The following revisions were not released, because they are unrelated to this call for testing: `${{ steps.promote.outputs.rejected }}`. ' + } + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: 'The following revisions were released to the `${{ steps.promote.outputs.channel }}` channel: `${{ steps.promote.outputs.revisions }}`' + body: message }) - name: Close call for testing issue @@ -147,7 +160,7 @@ runs: uses: actions/github-script@v7 with: script: | - if ("${{ steps.promote.outputs.done }}" === "done") { + if ("${{ steps.promote.outputs.done }}" === "done" && "${{ steps.promote.outputs.revisions }}".length > 0) { github.rest.issues.update({ issue_number: context.issue.number, owner: context.repo.owner,