From 903bb48f864b2f0fb35f9ecdd86d2fb5274c91f9 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 30 Mar 2024 23:00:23 -0400 Subject: [PATCH] Add version check to release workflow --- .../release-version-check.sh | 7 +++++++ .github/workflows/release.yaml | 19 ++++++++++++++++++- .github/workflows/update-map-data.yaml | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) 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 00748c8..25dca14 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,6 @@ name: release +run-name: Release ${{ github.event.repository.name }} ${{ inputs.version }} on: workflow_dispatch: @@ -8,6 +9,17 @@ on: description: "Release version number (e.g. 1.0.2)" required: true type: string + # When calling this workflow from another repo, ensure the following files are + # located in the local .github/workflow-resources directory: + # • release-checklist.R + # • release-pr-body.md + # • release-version-check.sh + workflow_call: + inputs: + version: + description: "Release version number (e.g. 1.0.2)" + required: true + type: string jobs: release: @@ -17,6 +29,11 @@ jobs: - 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 @@ -46,7 +63,7 @@ jobs: uses: jacobtomlinson/gha-find-replace@v3 with: find: "[unreleased]" - replace: "usmapdata ${{ inputs.version }}" + replace: "${{ github.event.repository.name }} ${{ inputs.version }}" include: "NEWS.md" regex: false diff --git a/.github/workflows/update-map-data.yaml b/.github/workflows/update-map-data.yaml index 618341c..86d66dd 100644 --- a/.github/workflows/update-map-data.yaml +++ b/.github/workflows/update-map-data.yaml @@ -1,5 +1,6 @@ name: update-map-data +run-name: Update map data on: schedule: