diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2022-09-29 13:14:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 13:14:39 +0300 |
commit | 2adac6056ba0de78317cfc9059d052d21e5f1aa7 (patch) | |
tree | e83e9a43980b9aeddb163a7acedf1b2bc81a17bb | |
parent | b40e9939a7d07b30a75625692874f02bcc9be18f (diff) |
Sync backport.yml changes from dotnet/runtime
-rw-r--r-- | .github/workflows/backport.yml | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index baf7a79a29a..5f6fe9827f2 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -2,15 +2,36 @@ name: Backport PR to branch on: issue_comment: types: [created] + schedule: + # once a day at 13:00 UTC + - cron: '0 13 * * *' permissions: - contents: read + contents: write + issues: write + pull-requests: write jobs: - backport: + cleanup_old_runs: + if: github.event.schedule == '0 13 * * *' + runs-on: ubuntu-20.04 permissions: - issues: write # for octokit.rest.issues.createComment in ./scripts/ci/actions/backport - pull-requests: write # for octokit.rest.pulls.create in ./scripts/ci/actions/backport + actions: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Delete old workflow runs + run: | + _UrlPath="/repos/$GITHUB_REPOSITORY/actions/workflows" + _CurrentWorkflowID="$(gh api -X GET "$_UrlPath" | jq '.workflows[] | select(.name == '\""$GITHUB_WORKFLOW"\"') | .id')" + + # delete workitems which are 'completed'. (other candidate values of status field are: 'queued' and 'in_progress') + + gh api -X GET "$_UrlPath/$_CurrentWorkflowID/runs" --paginate \ + | jq '.workflow_runs[] | select(.status == "completed") | .id' \ + | xargs -I{} gh api -X DELETE "/repos/$GITHUB_REPOSITORY/actions/runs"/{} + + backport: if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/backport to') runs-on: ubuntu-20.04 steps: @@ -23,7 +44,7 @@ jobs: if (context.eventName !== "issue_comment") throw "Error: This action only works on issue_comment events."; // extract the target branch name from the trigger phrase containing these characters: a-z, A-Z, digits, forward slash, dot, hyphen, underscore - const regex = /\/backport to ([a-zA-Z\d\/\.\-\_]+)/; + const regex = /^\/backport to ([a-zA-Z\d\/\.\-\_]+)/; target_branch = regex.exec(context.payload.comment.body); if (target_branch == null) throw "Error: No backport branch found in the trigger phrase."; @@ -44,7 +65,19 @@ jobs: with: fetch-depth: 0 - name: Run backport - uses: ./scripts/ci/actions/backport + uses: ./eng/actions/backport with: target_branch: ${{ steps.target-branch-extractor.outputs.result }} auth_token: ${{ secrets.GITHUB_TOKEN }} + pr_description_template: | + Backport of #%source_pr_number% to %target_branch% + + /cc %cc_users% + + ## Customer Impact + + ## Testing + + ## Risk + + IMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary [package authoring](https://github.com/dotnet/runtime/blob/main/docs/project/library-servicing.md) and gotten it explicitly reviewed. |