Repository navigation
63 lines (62 loc) · 2.45 KB
/
Copy pathself-mutation.yml
File metadata and controls
63 lines (62 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".
name: self-mutation
on:
workflow_run:
workflows:
- build
types:
- completed
jobs:
check:
runs-on: ubuntu-latest
permissions:
actions: read
outputs:
has_patch: ${{ steps.find_patch.outputs.has_patch }}
if: "github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' && !startsWith(github.event.workflow_run.head_commit.message, 'chore: self mutation') && github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch != github.event.repository.default_branch"
steps:
- name: Find patch
id: find_patch
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: echo "has_patch=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/artifacts?name=repo.patch" --jq '.total_count > 0')" >> $GITHUB_OUTPUT
self-mutation:
needs: check
runs-on: ubuntu-latest
permissions:
actions: read
if: needs.check.outputs.has_patch == 'true'
steps:
- name: Download patch
id: download_patch
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333
with:
name: repo.patch
path: ${{ runner.temp }}
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
- name: Checkout
id: checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
ref: ${{ github.event.workflow_run.head_sha }}
repository: ${{ github.event.workflow_run.head_repository.full_name }}
- name: Apply patch
id: apply_patch
run: git apply ${{ runner.temp }}/repo.patch
- name: Set git identity
id: set_git_identity
run: |-
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Push changes
id: push_changes
env:
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |-
git add .
git commit -s -m "chore: self mutation"
git push --force-with-lease="refs/heads/$HEAD_BRANCH:$HEAD_SHA" origin "HEAD:refs/heads/$HEAD_BRANCH"