Remove long timeout labels #4
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: Remove long timeout labels | |
on: | |
workflow_run: | |
workflows: | |
- CI | |
- Manage long timeout labels | |
types: | |
- completed | |
env: | |
GH_REPO: ${{ github.repository }} | |
GH_NO_UPDATE_NOTIFIER: 1 | |
GH_PROMPT_DISABLED: 1 | |
LONG_TIMEOUT_LABEL: CI-long-timeout | |
HOMEBREW_NO_INSTALL_FROM_API: 1 | |
jobs: | |
check-label: | |
runs-on: ubuntu-latest | |
if: > | |
github.repository_owner == 'Homebrew' && | |
contains(fromJson('["pull_request", "pull_request_target"]'), github.event.workflow_run.event) && | |
github.event.workflow_run.conclusion != 'skipped' | |
outputs: | |
pull-number: ${{ steps.pr.outputs.number }} | |
long-timeout: ${{ steps.check.outputs.long-timeout }} | |
permissions: | |
contents: read | |
actions: read # for `gh run download` | |
pull-requests: read # for `gh api` | |
steps: | |
- name: Download `pull-number` artifact | |
uses: Homebrew/actions/gh-try-download@master | |
with: | |
artifact-name: pull-number | |
workflow-id: ${{ github.event.workflow_run.id }} | |
- run: echo "number=$(cat number)" >> "$GITHUB_OUTPUT" | |
id: pr | |
- name: Check PR labels | |
id: check | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PR: ${{ steps.pr.outputs.number }} | |
run: | | |
long_timeout="$( | |
gh api \ | |
--header 'Accept: application/vnd.github+json' \ | |
--header 'X-GitHub-Api-Version: 2022-11-28' \ | |
"repos/$GH_REPO/pulls/$PR" \ | |
--jq "any(.labels[].name; .== \"$LONG_TIMEOUT_LABEL\")" | |
)" | |
echo "long-timeout=$long_timeout" >> "$GITHUB_OUTPUT" | |
remove-label: | |
needs: check-label | |
if: > | |
needs.check-label.result == 'success' && | |
fromJson(needs.check-label.outputs.long-timeout) | |
runs-on: ubuntu-latest | |
container: | |
image: ghcr.io/homebrew/ubuntu22.04:master | |
defaults: | |
run: | |
shell: bash | |
env: | |
PR: ${{ needs.check-label.outputs.pull-number }} | |
permissions: | |
contents: read | |
actions: read # for `GitHub.get_workflow_run` | |
checks: read # for `GitHub.get_workflow_run` | |
pull-requests: write # for `gh pr edit` | |
repository-projects: write # for `gh pr edit` | |
steps: | |
- name: Set up Homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
with: | |
test-bot: false | |
- name: Check CI status | |
id: check | |
env: | |
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: brew check-ci-status "$PR" | |
- name: Remove long timeout label | |
if: fromJson(steps.check.outputs.allow-long-timeout-label-removal) | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
echo "::notice ::Removing \`$LONG_TIMEOUT_LABEL\` label from PR #$PR" | |
gh pr edit "$PR" --remove-label "$LONG_TIMEOUT_LABEL" |