# ~~ Generated by projen. To modify, edit .projenrc.ts and run "yarn 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"