fork/team
git clone https://git.julia.blue/fork/team
9e6d700
remove-fuchsia
1# This workflow executes a dry-run of the sync-team tool after a push to any pull request. 2# This allows us to see which changes would be applied to live services after the PR 3# would be merged. 4# 5# The workflow uses the `workflow_run` trigger, which should always run in the default branch of 6# this repository. This is required so that the workflow has permissions to post PR comments. 7# We should not check out any code from the PR, as it could present a security hazard. 8# Instead, we simply download a GitHub artifact with a directory of JSON files and use that as 9# input for sync-team. 10# This artifact is created and uploaded on PR pushes using the CI workflow in `main.yml`. 11# Details about `workflow_run`: 12# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run: 13name : sync-team dry-run 14 15on : 16workflow_run : 17workflows : [ CI ] 18types : 19- completed 20 21jobs : 22dry-run : 23runs-on : ubuntu-latest 24if : ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} 25concurrency : 26# Only run this once at a time on any given PR 27group : dry-run-${{ github.event.workflow_run.head_branch }} 28cancel-in-progress : true 29permissions : 30pull-requests : write 31steps : 32- uses : actions/checkout@v4 33with : 34repository : rust-lang/sync-team 35persist-credentials : false 36 37- name : Install Rust Stable 38run : | 39rustc -vV 40rustup update stable 41rustup default stable 42rustc -vV 43 44# Pinning a specific version to avoid surprises 45- uses : Swatinem/rust-cache@27b8ea9368cf428f0bfe41b0876b1a7e809d9844 46 47- name : Download built JSON API 48uses : actions/download-artifact@v4 49with : 50name : team-api-output 51path : team-api 52run-id : ${{ github.event.workflow_run.id }} 53github-token : ${{ secrets.GITHUB_TOKEN }} 54 55# GitHub tokens generated from GitHub Apps can access resources from one organization, 56# so we need to generate a token for each organization. 57- name : Generate GitHub token (rust-lang) 58uses : actions/create-github-app-token@v1 59id : rust-lang-token 60with : 61# GitHub App ID secret name 62app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 63# GitHub App private key secret name 64private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 65# Set the owner, so the token can be used in all repositories 66owner : rust-lang 67 68- name : Generate GitHub token (rust-lang-ci) 69uses : actions/create-github-app-token@v1 70id : rust-lang-ci-token 71with : 72app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 73private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 74owner : rust-lang-ci 75 76- name : Generate GitHub token (rust-lang-deprecated) 77uses : actions/create-github-app-token@v1 78id : rust-lang-deprecated-token 79with : 80app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 81private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 82owner : rust-lang-deprecated 83 84- name : Generate GitHub token (rust-lang-nursery) 85uses : actions/create-github-app-token@v1 86id : rust-lang-nursery-token 87with : 88app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 89private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 90owner : rust-lang-nursery 91 92- name : Generate GitHub token (bors-rs) 93uses : actions/create-github-app-token@v1 94id : bors-rs-token 95with : 96app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 97private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 98owner : bors-rs 99 100- name : Generate GitHub token (rust-analyzer) 101uses : actions/create-github-app-token@v1 102id : rust-analyzer-token 103with : 104app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 105private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 106owner : rust-analyzer 107 108- name : Generate GitHub token (rust-embedded) 109uses : actions/create-github-app-token@v1 110id : rust-embedded-token 111with : 112app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 113private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 114owner : rust-embedded 115 116- name : Generate GitHub token (rust-dev-tools) 117uses : actions/create-github-app-token@v1 118id : rust-dev-tools-token 119with : 120app-id : ${{ secrets.SYNC_TEAM_GH_APP_ID }} 121private-key : ${{ secrets.SYNC_TEAM_GH_APP_PRIVATE_KEY }} 122owner : rust-dev-tools 123 124- name : Run sync-team dry-run check 125env : 126GITHUB_TOKEN_RUST_LANG : ${{ steps.rust-lang-token.outputs.token }} 127GITHUB_TOKEN_RUST_LANG_CI : ${{ steps.rust-lang-ci-token.outputs.token }} 128GITHUB_TOKEN_RUST_LANG_DEPRECATED : ${{ steps.rust-lang-deprecated-token.outputs.token }} 129GITHUB_TOKEN_RUST_LANG_NURSERY : ${{ steps.rust-lang-nursery-token.outputs.token }} 130GITHUB_TOKEN_BORS_RS : ${{ steps.bors-rs-token.outputs.token }} 131GITHUB_TOKEN_RUST_ANALYZER : ${{ steps.rust-analyzer-token.outputs.token }} 132GITHUB_TOKEN_RUST_EMBEDDED : ${{ steps.rust-embedded-token.outputs.token }} 133GITHUB_TOKEN_RUST_DEV_TOOLS : ${{ steps.rust-dev-tools-token.outputs.token }} 134# This applies pipefail, so that the tee pipeline below fails when sync-team fails. 135shell : bash 136run : | 137# Perform build and execution separately to avoid any potential output from 138# cargo leaking into the output file. 139cargo build --release 140./target/release/sync-team print-plan --services github --team-json team-api 2>&1 | tee -a output.txt 141 142- name : Prepare comment 143run : | 144cat > comment.txt << EOL 145<details> 146<summary>Dry-run check results</summary> 147<pre><code> 148EOL 149cat output.txt >> comment.txt 150printf "</pre></code>\n</details>\n" >> comment.txt 151 152cat comment.txt 153 154- name : Extract PR number 155run : | 156# We read the PR number that is stored in the uploaded archive 157# and check that it is an integer (as the workflow could upload whatever it wants). 158UNSANITIZED_PR=`cat team-api/pr.txt` 159if [[ ${UNSANITIZED_PR} =~ ^[0-9]+$ ]]; then 160echo "PR_NUMBER=${UNSANITIZED_PR}" >> $GITHUB_ENV 161else 162echo "Invalid PR number passed: ${UNSANITIZED_PR}" 163exit 1 164fi 165 166- name : Send comment 167env : 168GH_TOKEN : ${{ github.token }} 169run : | 170 PR=${PR_NUMBER} 171 echo "Pull request ${PR}" 172 173 # --edit-last doesn't work if there is no previous comment, so we have to figure out 174 # if we should create a comment or not 175 if gh issue view ${PR} --repo rust-lang/team --json comments \ 176 --jq '.comments.[].author.login' | grep --quiet --fixed-strings "github-actions"; then 177 echo "Editing comment" 178 gh pr comment ${PR} --repo rust-lang/team --body-file comment.txt --edit-last 179 else 180 echo "Creating new comment" 181 gh pr comment ${PR} --repo rust-lang/team --body-file comment.txt 182 fi