From 846b575dce262cf397babbf8ac80a82a473d184f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 31 Jan 2024 13:56:24 +0100 Subject: [PATCH] CI updates This is done by the automated script named upgrade-c2cciutils-to-1.7 --- .../workflows/delete-old-workflows-run.yaml | 23 --- .github/workflows/dependency-auto-review.yaml | 25 ---- .github/workflows/pr-checks.yaml | 4 +- .../workflows/pull-request-automation.yaml | 139 ++++++++++++++++++ ci/config.yaml | 5 +- 5 files changed, 141 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/delete-old-workflows-run.yaml delete mode 100644 .github/workflows/dependency-auto-review.yaml create mode 100644 .github/workflows/pull-request-automation.yaml diff --git a/.github/workflows/delete-old-workflows-run.yaml b/.github/workflows/delete-old-workflows-run.yaml deleted file mode 100644 index ca093a38..00000000 --- a/.github/workflows/delete-old-workflows-run.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Delete old workflow runs - -on: - schedule: - - cron: '0 0 * * *' - -env: - HAS_SECRETS: ${{ secrets.HAS_SECRETS }} - -jobs: - build: - runs-on: ubuntu-22.04 - timeout-minutes: 25 - name: Delete old workflow runs - - steps: - - name: Delete old workflow runs - uses: MajorScruffy/delete-old-workflow-runs@v0.3.0 - with: - repository: ${{ github.repository }} - older-than-seconds: 43200000 # 500 days - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/dependency-auto-review.yaml b/.github/workflows/dependency-auto-review.yaml deleted file mode 100644 index 8a0eb528..00000000 --- a/.github/workflows/dependency-auto-review.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Auto reviews updates - -on: - pull_request: - types: - - opened - - reopened - -jobs: - auto-merge: - name: Auto reviews updates - runs-on: ubuntu-22.04 - timeout-minutes: 5 - if: github.event.pull_request.user.login == 'renovate[bot]' - - steps: - - uses: actions/github-script@v6 - with: - script: |- - github.rest.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - event: 'APPROVE', - }) diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 099c9159..75ee157b 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -5,9 +5,7 @@ on: types: - opened - reopened - - labeled - - unlabeled - - edit + - edited - synchronize env: diff --git a/.github/workflows/pull-request-automation.yaml b/.github/workflows/pull-request-automation.yaml new file mode 100644 index 00000000..d9d9e860 --- /dev/null +++ b/.github/workflows/pull-request-automation.yaml @@ -0,0 +1,139 @@ +name: Auto reviews, merge and close pull requests + +on: + pull_request: + types: + - opened + - reopened + - closed + pull_request_target: + types: + - closed + +jobs: + auto-merge: + name: Auto reviews, merge and close pull requests + runs-on: ubuntu-22.04 + timeout-minutes: 5 + + steps: + - name: Print event + run: echo "${GITHUB}" | jq + env: + GITHUB: ${{ toJson(github) }} + - name: Print context + uses: actions/github-script@v7 + with: + script: |- + console.log(context); + - name: Auto reviews Renovate updates + uses: actions/github-script@v7 + with: + script: |- + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: 'APPROVE', + }) + if: |- + github.event.pull_request.user.login == 'renovate[bot]' + && (github.event.action == 'opened' + || github.event.action == 'reopened') + - name: Auto review and merge dpkg updates + uses: actions/github-script@v7 + with: + script: |- + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: 'APPROVE', + }); + github.graphql(` + mutation { + enablePullRequestAutoMerge(input: { + pullRequestId: "${context.payload.pull_request.node_id}", + mergeMethod: SQUASH, + }) { + pullRequest { + autoMergeRequest { + enabledAt + } + } + } + } + `) + if: |- + github.event.pull_request.user.login == 'c2c-bot-gis-ci' + && startsWith(github.head_ref, 'dpkg-update/') + && (github.event.action == 'opened' + || github.event.action == 'reopened') + - name: Auto review and merge snyk auto fix + uses: actions/github-script@v7 + with: + script: |- + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: 'APPROVE', + }); + github.graphql(` + mutation { + enablePullRequestAutoMerge(input: { + pullRequestId: "${context.payload.pull_request.node_id}", + mergeMethod: SQUASH, + }) { + pullRequest { + autoMergeRequest { + enabledAt + } + } + } + } + `) + if: |- + github.event.pull_request.user.login == 'c2c-bot-gis-ci' + && startsWith(github.head_ref, 'snyk-fix/') + && (github.event.action == 'opened' + || github.event.action == 'reopened') + - name: Restart audit workflow + uses: actions/github-script@v7 + with: + script: |- + let runs = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'audit.yaml', + per_page: 1, + }); + runs = runs.data.workflow_runs; + if (runs.length == 1 && runs[0].status != 'success') { + console.log(`Rerun workflow ${runs[0].id} ${runs[0].status}`); + github.rest.actions.reRunWorkflowFailedJobs({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: runs[0].id, + }); + } + if: |- + github.event.pull_request.user.login == 'c2c-bot-gis-ci' + && (startsWith(github.head_ref, 'snyk-fix/') + || startsWith(github.head_ref, 'dpkg-update/')) + && github.event.action == 'closed' + && github.event.pull_request.merged == true + - name: Auto close pre-commit.ci autoupdate + uses: actions/github-script@v7 + with: + script: |- + github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + state: 'closed', + }); + if: |- + github.event.pull_request.user.login == 'pre-commit-ci' + && (github.event.action == 'opened' + || github.event.action == 'reopened') diff --git a/ci/config.yaml b/ci/config.yaml index 3e504e7a..d0ff8d87 100644 --- a/ci/config.yaml +++ b/ci/config.yaml @@ -1,10 +1,7 @@ # yaml-language-server: $schema=https://raw.githubusercontent.com/camptocamp/c2cciutils/1.6.13/c2cciutils/schema.json checks: - codespell: - arguments: - - --ignore-words-list=astroid,ro - + codespell: false audit: snyk: files_no_install: