From 97a8edacff0c8e5c7a7fd869b68b07521a7124a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 27 Oct 2024 06:09:52 +0100 Subject: [PATCH] ci: Import from actions-sync, check carefully (#526) --- .github/workflows/R-CMD-check-status.yaml | 5 +- .github/workflows/R-CMD-check.yaml | 95 ++++++++++++++++++- .github/workflows/pkgdown.yaml | 2 +- .github/workflows/update-snapshots/action.yml | 9 +- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/.github/workflows/R-CMD-check-status.yaml b/.github/workflows/R-CMD-check-status.yaml index 15860acbb..b9bdf4e4a 100644 --- a/.github/workflows/R-CMD-check-status.yaml +++ b/.github/workflows/R-CMD-check-status.yaml @@ -16,11 +16,10 @@ jobs: name: "Update commit status" - # Only run if triggered by rcc workflow - if: github.event.workflow_run.name == 'rcc' - steps: - name: "Update commit status" + # Only run if triggered by rcc workflow + if: github.event.workflow_run.name == 'rcc' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 428cec137..e2234cde6 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -18,9 +18,17 @@ on: workflow_dispatch: inputs: ref: - description: "Branch or tag to check out" + description: "Branch, tag, or commit to check out" required: false default: "main" + versions-matrix: + description: "Create a matrix of R versions" + type: boolean + default: false + dep-suggests-matrix: + description: "Create a matrix of suggested dependencies" + type: boolean + default: false merge_group: types: - checks_requested @@ -33,6 +41,7 @@ concurrency: name: rcc + jobs: rcc-smoke: runs-on: ubuntu-latest @@ -51,6 +60,38 @@ jobs: with: ref: ${{ inputs.ref }} + - name: Update status for rcc + # FIXME: Wrap into action + if: github.event_name == 'workflow_dispatch' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Check status of this workflow + state="pending" + sha=${{ inputs.ref }} + if [ -z "${sha}" ]; then + sha=${{ github.head_ref }} + fi + if [ -z "${sha}" ]; then + sha=${{ github.sha }} + fi + sha=$(git rev-parse ${sha}) + + html_url=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/actions/runs/${{ github.run_id }} | jq -r .html_url) + + description="${{ github.workflow }} / ${{ github.job }}" + + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/statuses/${sha} \ + -f "state=${state}" -f "target_url=${html_url}" -f "description=${description}" -f "context=rcc" + shell: bash + - uses: ./.github/workflows/rate-limit with: token: ${{ secrets.GITHUB_TOKEN }} @@ -66,25 +107,29 @@ jobs: cache-version: rcc-smoke-2 needs: check, website # Beware of using dev pkgdown here, has brought in dev dependencies in the past - extra-packages: any::rcmdcheck r-lib/roxygen2 any::decor r-lib/styler pkgdown deps::. + extra-packages: any::rcmdcheck r-lib/roxygen2 any::decor r-lib/styler r-lib/pkgdown@f-readme-tweak deps::. - name: Install package run: | - R CMD INSTALL . + _R_SHLIB_STRIP_=true R CMD INSTALL . shell: bash - uses: ./.github/workflows/custom/after-install if: hashFiles('.github/workflows/custom/after-install/action.yml') != '' - id: versions-matrix - # Only run for pull requests if the base repo is different from the head repo, always run for other events - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + # Only run for pull requests if the base repo is different from the head repo, not for workflow_dispatch if not requested, always run for other events + if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository) && (github.event_name != 'workflow_dispatch' || inputs.versions-matrix) uses: ./.github/workflows/versions-matrix - id: dep-suggests-matrix + # Not for workflow_dispatch if not requested, always run for other events + if: github.event_name != 'workflow_dispatch' || inputs.dep-suggests-matrix uses: ./.github/workflows/dep-suggests-matrix - uses: ./.github/workflows/update-snapshots + with: + base: ${{ inputs.ref || github.head_ref }} - uses: ./.github/workflows/style @@ -120,6 +165,46 @@ jobs: name: rcc-smoke-sha path: rcc-smoke-sha.txt + - name: Update status for rcc + # FIXME: Wrap into action + if: always() && github.event_name == 'workflow_dispatch' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Check status of this workflow + if [ "${{ job.status }}" == "success" ]; then + state="success" + else + state="failure" + fi + + sha=${{ steps.commit.outputs.sha }} + if [ -z "${sha}" ]; then + sha=${{ inputs.ref }} + fi + if [ -z "${sha}" ]; then + sha=${{ github.head_ref }} + fi + if [ -z "${sha}" ]; then + sha=${{ github.sha }} + fi + sha=$(git rev-parse ${sha}) + + html_url=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/actions/runs/${{ github.run_id }} | jq -r .html_url) + + description="${{ github.workflow }} / ${{ github.job }}" + + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/statuses/${sha} \ + -f "state=${state}" -f "target_url=${html_url}" -f "description=${description}" -f "context=rcc" + shell: bash + rcc-smoke-check-matrix: runs-on: ubuntu-latest diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 09dc06382..6afddb16f 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -42,7 +42,7 @@ jobs: install-r: false cache-version: pkgdown-2 needs: website - extra-packages: pkgdown local::. + extra-packages: r-lib/pkgdown@f-readme-tweak local::. - uses: ./.github/workflows/custom/after-install if: hashFiles('.github/workflows/custom/after-install/action.yml') != '' diff --git a/.github/workflows/update-snapshots/action.yml b/.github/workflows/update-snapshots/action.yml index 6322dc156..5ee7e3ecc 100644 --- a/.github/workflows/update-snapshots/action.yml +++ b/.github/workflows/update-snapshots/action.yml @@ -3,6 +3,11 @@ description: > This action will run `testthat::test_local()` for tests that seem to use snapshots, this is determined by reading and grepping the test files. If the tests are failing, snapshots are updated, and a pull request is opened. +inputs: + base: + description: "The base branch to create the pull request against." + required: false + default: "main" runs: using: "composite" @@ -67,8 +72,8 @@ runs: id: cpr uses: peter-evans/create-pull-request@v6 with: - base: ${{ github.head_ref }} - branch: snapshot-${{ github.ref_name }}-${{ github.job }}-${{ steps.matrix-desc.outputs.branch }} + base: ${{ inputs.base }} + branch: snapshot-${{ inputs.base }}-${{ github.job }}-${{ steps.matrix-desc.outputs.branch }} delete-branch: true title: "test: Snapshot updates for ${{ github.job }} (${{ steps.matrix-desc.outputs.text }})" body: "Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action${{ github.event.number && format(' for #{0}', github.event.number) || '' }}."