From e751f3ac7c4c6596f16b87dd5d81ae2912eba753 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 21:41:41 -0400 Subject: [PATCH 01/11] Add version number check in release workflow --- .github/workflow-resources/version-check.R | 6 ++++++ .github/workflows/release.yaml | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .github/workflow-resources/version-check.R diff --git a/.github/workflow-resources/version-check.R b/.github/workflow-resources/version-check.R new file mode 100644 index 0000000..3fdcc4f --- /dev/null +++ b/.github/workflow-resources/version-check.R @@ -0,0 +1,6 @@ +verify_version <- function(new_version) { + current_version <- desc::desc_get_version() + if (utils::compareVersion(new_version, current_version) != 1) { + Sys.setenv(INVALID_VERSION = "true") + } +} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 68e3ee5..c2c2940 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,6 @@ name: release +run-name: release ${{ inputs.version }} on: workflow_dispatch: @@ -28,6 +29,22 @@ jobs: any::rhub github::r-lib/revdepcheck + - name: Check version number + env: + VERSION: ${{ inputs.version }} + run: | + source(".github/workflow_resources/version-check.R") + verify_version(Sys.getenv("VERSION")) + shell: Rscript {0} + + - name: Version number error + if: ${{ INVALID_VERSION }} + run: | + if [ "$INVALID_VERSION" = "true" ]; then + echo "::error title=Invalid version::Provided version number must be higher than the current version (${{ inputs.version }})" + exit 1 + fi + - name: Run release checks env: EMAIL: ${{ secrets.RHUB_EMAIL }} From 1264640fa8431a5b33d6a14c6ac9e406d71fe520 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 21:44:41 -0400 Subject: [PATCH 02/11] Remove extra invalid_version conditional in release workflow --- .github/workflows/release.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c2c2940..9a7018f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -38,7 +38,6 @@ jobs: shell: Rscript {0} - name: Version number error - if: ${{ INVALID_VERSION }} run: | if [ "$INVALID_VERSION" = "true" ]; then echo "::error title=Invalid version::Provided version number must be higher than the current version (${{ inputs.version }})" From c8794a3de5ad76e69fb58ada41d5d58cb69bc400 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 22:06:58 -0400 Subject: [PATCH 03/11] Replace R-based version check with bash script in release.yaml --- .github/workflow-resources/version-check.R | 6 ------ .github/workflows/release.yaml | 25 +++++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 .github/workflow-resources/version-check.R diff --git a/.github/workflow-resources/version-check.R b/.github/workflow-resources/version-check.R deleted file mode 100644 index 3fdcc4f..0000000 --- a/.github/workflow-resources/version-check.R +++ /dev/null @@ -1,6 +0,0 @@ -verify_version <- function(new_version) { - current_version <- desc::desc_get_version() - if (utils::compareVersion(new_version, current_version) != 1) { - Sys.setenv(INVALID_VERSION = "true") - } -} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9a7018f..10dbd64 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,6 +18,16 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Check version number + run: | + current_version=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') + input_version="${{ steps.read_version.outputs.version }}" + + if [ "$(printf '%s\n' "$input_version" "$current_version" | sort -V | head -n1)" = "$input_version" ]; then + echo "::error title=Invalid version::Provided version number must be higher than the current version (${{ inputs.version }})." + exit 1 + fi + - name: Setup R uses: r-lib/actions/setup-r@v2 @@ -29,21 +39,6 @@ jobs: any::rhub github::r-lib/revdepcheck - - name: Check version number - env: - VERSION: ${{ inputs.version }} - run: | - source(".github/workflow_resources/version-check.R") - verify_version(Sys.getenv("VERSION")) - shell: Rscript {0} - - - name: Version number error - run: | - if [ "$INVALID_VERSION" = "true" ]; then - echo "::error title=Invalid version::Provided version number must be higher than the current version (${{ inputs.version }})" - exit 1 - fi - - name: Run release checks env: EMAIL: ${{ secrets.RHUB_EMAIL }} From bb9d3e99d4012f9dc1ec64aeae80a879a7038c2c Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 22:08:43 -0400 Subject: [PATCH 04/11] Fix inputs.version env in version check" --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 10dbd64..42f7312 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,10 +21,10 @@ jobs: - name: Check version number run: | current_version=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') - input_version="${{ steps.read_version.outputs.version }}" + input_version="${{ inputs.version }}" if [ "$(printf '%s\n' "$input_version" "$current_version" | sort -V | head -n1)" = "$input_version" ]; then - echo "::error title=Invalid version::Provided version number must be higher than the current version (${{ inputs.version }})." + echo "::error title=Invalid version::Provided version number must be higher than the current version ($current_version)." exit 1 fi From 468b5a92204e0bcf760977533902a72a2af7ac48 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 22:11:50 -0400 Subject: [PATCH 05/11] Improve run-name in release.yaml --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 42f7312..a5bd335 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,6 @@ name: release -run-name: release ${{ inputs.version }} +run-name: Release usmap ${{ inputs.version }} on: workflow_dispatch: From c87702f215e3763775a51beb67845f0a765bf610 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 22:25:28 -0400 Subject: [PATCH 06/11] Use intermediate env var for input version --- .github/workflows/release.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a5bd335..46e1c54 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,12 +19,13 @@ jobs: uses: actions/checkout@v4 - name: Check version number + env: + INPUT_VERSION: ${{ inputs.version }} run: | - current_version=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') - input_version="${{ inputs.version }}" + CURRENT_VERSION=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') - if [ "$(printf '%s\n' "$input_version" "$current_version" | sort -V | head -n1)" = "$input_version" ]; then - echo "::error title=Invalid version::Provided version number must be higher than the current version ($current_version)." + if [ "$(printf '%s\n' "$INPUT_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$INPUT_VERSION" ]; then + echo "::error title=Invalid version::Provided version number must be higher than the current version ($CURRENT_VERSION)." exit 1 fi From 32571aaf3793f85d30980c0557ceed66b47d59a2 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 22:40:11 -0400 Subject: [PATCH 07/11] Move version check to separate bash script --- .github/workflow-resources/release-version-check.sh | 7 +++++++ .github/workflows/release.yaml | 12 +++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100755 .github/workflow-resources/release-version-check.sh diff --git a/.github/workflow-resources/release-version-check.sh b/.github/workflow-resources/release-version-check.sh new file mode 100755 index 0000000..3463c99 --- /dev/null +++ b/.github/workflow-resources/release-version-check.sh @@ -0,0 +1,7 @@ +# assumes $INPUT_VERSION is set to the selected release version +CURRENT_VERSION=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') + +if [ "$(printf '%s\n' "$INPUT_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$INPUT_VERSION" ]; then + echo "::error title=Invalid version::Provided version number must be higher than the current version ($CURRENT_VERSION)." + exit 1 +fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 46e1c54..e05bda4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,6 @@ name: release -run-name: Release usmap ${{ inputs.version }} +run-name: Release ${{ github.event.repository.name }} ${{ inputs.version }} on: workflow_dispatch: @@ -21,13 +21,7 @@ jobs: - name: Check version number env: INPUT_VERSION: ${{ inputs.version }} - run: | - CURRENT_VERSION=$(echo "$(cat DESCRIPTION)" | grep "Version:" | awk '{print $2}') - - if [ "$(printf '%s\n' "$INPUT_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$INPUT_VERSION" ]; then - echo "::error title=Invalid version::Provided version number must be higher than the current version ($CURRENT_VERSION)." - exit 1 - fi + run: .github/workflow-resources/release-version-check.sh - name: Setup R uses: r-lib/actions/setup-r@v2 @@ -58,7 +52,7 @@ jobs: uses: jacobtomlinson/gha-find-replace@v3 with: find: "[unreleased]" - replace: "usmap ${{ inputs.version }}" + replace: "${{ github.event.repository.name }} ${{ inputs.version }}" include: "NEWS.md" regex: false From a9c01f89194ea91dd2d153c7e04bef5d2c4b9962 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 23:31:27 -0400 Subject: [PATCH 08/11] Set release workflow to re-use usmapdata release.yaml --- .github/workflows/release.yaml | 79 ++-------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e05bda4..3c0caa9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,78 +12,7 @@ on: jobs: release: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Check version number - env: - INPUT_VERSION: ${{ inputs.version }} - run: .github/workflow-resources/release-version-check.sh - - - name: Setup R - uses: r-lib/actions/setup-r@v2 - - - name: Install R dependencies - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: | - any::devtools - any::rhub - github::r-lib/revdepcheck - - - name: Run release checks - env: - EMAIL: ${{ secrets.RHUB_EMAIL }} - TOKEN: ${{ secrets.RHUB_TOKEN }} - VERSION: ${{ inputs.version }} - run: | - source(".github/workflow-resources/release-checklist.R") - release_checklist( - Sys.getenv("EMAIL"), - Sys.getenv("TOKEN"), - Sys.getenv("VERSION") - ) - shell: Rscript {0} - - - name: Update NEWS.md version - uses: jacobtomlinson/gha-find-replace@v3 - with: - find: "[unreleased]" - replace: "${{ github.event.repository.name }} ${{ inputs.version }}" - include: "NEWS.md" - regex: false - - - name: Import GPG signing key - uses: crazy-max/ghaction-import-gpg@v6 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} - git_user_signingkey: true - git_commit_gpgsign: true - - - name: Render PR body - id: pr-body - uses: chuhlomin/render-template@v1 - with: - template: .github/workflow-resources/release-pr-body.md - vars: | - version: ${{ inputs.version }} - - - name: Open pull request - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.BOT_PAT }} - author: ${{ secrets.BOT_USER }} - committer: ${{ secrets.BOT_USER }} - commit-message: "[automated] Prepare for ${{ inputs.version }} release" - branch: release/${{ inputs.version }} - title: Release version ${{ inputs.version }} - body: ${{ steps.pr-body.outputs.result }} - reviewers: pdil - assignees: pdil - labels: release - delete-branch: true - draft: true + uses: pdil/usmapdata/.github/workflows/release.yaml@master + secrets: inherit + with: + version: ${{ inputs.version }} From c0ae1577565245a45d8ab68443a3dc11cacfdc2a Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sun, 31 Mar 2024 17:19:59 -0400 Subject: [PATCH 09/11] Set other workflows to re-use usmapdata workflow scripts --- .github/workflows/check.yaml | 45 +++---------------------- .github/workflows/lintr.yml | 39 +++------------------- .github/workflows/test-coverage.yaml | 49 ++++------------------------ 3 files changed, 14 insertions(+), 119 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 9bb6413..d43c7fd 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,4 +1,5 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples + +name: check on: push: @@ -6,45 +7,7 @@ on: pull_request: branches: master -name: check - jobs: check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - {os: macos-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: yes - - steps: - - uses: actions/checkout@v4 - - - uses: r-lib/actions/setup-pandoc@v2 - - - uses: r-lib/actions/setup-r@v2 - with: - r-version: ${{ matrix.config.r }} - http-user-agent: ${{ matrix.config.http-user-agent }} - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::rcmdcheck - needs: check - - - uses: r-lib/actions/check-r-package@v2 - with: - upload-snapshots: true - build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' + uses: pdil/usmapdata/.github/workflows/check.yaml@master + secrets: inherit diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yml index b80661f..de0d74e 100644 --- a/.github/workflows/lintr.yml +++ b/.github/workflows/lintr.yml @@ -1,47 +1,16 @@ -# lintr provides static code analysis for R. -# It checks for adherence to a given style, -# identifying syntax errors and possible semantic issues, -# then reports them to you so you can take action. -# More details at https://lintr.r-lib.org/ name: lintr on: push: - branches: [ "master" ] + branches: master pull_request: - branches: [ "master" ] + branches: master permissions: contents: read jobs: lintr: - name: Run lintr scanning - runs-on: ubuntu-latest - permissions: - contents: read # for checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup R - uses: r-lib/actions/setup-r@v2 - - - name: Setup lintr - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: lintr - - - name: Run lintr - run: lintr::sarif_output(lintr::lint_dir("."), "lintr-results.sarif") - shell: Rscript {0} - continue-on-error: true - - - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: lintr-results.sarif - wait-for-processing: true + uses: pdil/usmapdata/.github/workflows/lintr.yaml@master + secrets: inherit diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9b5dcb7..b3ed8fe 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,50 +1,13 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples + +name: test-coverage on: push: - branches: [main, master] + branches: master pull_request: - branches: [main, master] - -name: test-coverage + branches: master jobs: test-coverage: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v4 - - - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::covr - needs: coverage - - - name: Test coverage - run: | - covr::codecov( - quiet = FALSE, - clean = FALSE, - install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") - ) - shell: Rscript {0} - - - name: Show testthat output - if: always() - run: | - ## -------------------------------------------------------------------- - find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload test results - if: failure() - uses: actions/upload-artifact@v4 - with: - name: coverage-test-failures - path: ${{ runner.temp }}/package + uses: pdil/usmapdata/.github/workflows/test-coverage.yaml@master + secrets: inherit From 8fbbac8c898abcf654af999e019f6114c87bb119 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sun, 31 Mar 2024 17:33:51 -0400 Subject: [PATCH 10/11] Fix lintr.yaml permissions --- .github/workflows/{lintr.yml => lintr.yaml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{lintr.yml => lintr.yaml} (61%) diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yaml similarity index 61% rename from .github/workflows/lintr.yml rename to .github/workflows/lintr.yaml index de0d74e..d055364 100644 --- a/.github/workflows/lintr.yml +++ b/.github/workflows/lintr.yaml @@ -7,10 +7,10 @@ on: pull_request: branches: master -permissions: - contents: read - jobs: lintr: + permissions: + # for github/codeql-action/upload-sarif to upload SARIF results + security-events: write uses: pdil/usmapdata/.github/workflows/lintr.yaml@master secrets: inherit From eeb8959cc422ce290ed8a407c0784602c8f4717f Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sun, 31 Mar 2024 17:35:13 -0400 Subject: [PATCH 11/11] Rename lintr.yaml to lint.yaml --- .github/workflows/{lintr.yaml => lint.yaml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{lintr.yaml => lint.yaml} (72%) diff --git a/.github/workflows/lintr.yaml b/.github/workflows/lint.yaml similarity index 72% rename from .github/workflows/lintr.yaml rename to .github/workflows/lint.yaml index d055364..34c5868 100644 --- a/.github/workflows/lintr.yaml +++ b/.github/workflows/lint.yaml @@ -1,5 +1,5 @@ -name: lintr +name: lint on: push: @@ -8,9 +8,9 @@ on: branches: master jobs: - lintr: + lint: permissions: # for github/codeql-action/upload-sarif to upload SARIF results security-events: write - uses: pdil/usmapdata/.github/workflows/lintr.yaml@master + uses: pdil/usmapdata/.github/workflows/lint.yaml@master secrets: inherit