From d2bc11af71f4386c79c6a192ba8168ce30657b71 Mon Sep 17 00:00:00 2001 From: Joel Dixon Date: Thu, 11 Jan 2024 16:10:43 -0600 Subject: [PATCH 1/5] Don't commit version changes if empty --- .github/workflows/Publish_NIMS.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml index b7764154f..9ae8b1ee8 100644 --- a/.github/workflows/Publish_NIMS.yml +++ b/.github/workflows/Publish_NIMS.yml @@ -56,10 +56,14 @@ jobs: - name: Commit file changes if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add . - git commit -m "Promote NIMS package version and update Sphinx generated files in _docs" -a + if [ -n "$(git status --porcelain)" ]; then + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add . + git commit -m "Promote NIMS and NIMG package version" -a + else + echo "No changes. Not committing version changes."; + fi - name: Push changes to the appropriate branch if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} From 8cda06c49d2f7239640166e21cab8ac3b5e78b28 Mon Sep 17 00:00:00 2001 From: Joel Dixon Date: Thu, 11 Jan 2024 16:34:36 -0600 Subject: [PATCH 2/5] Add conditional for pushing commit to branch --- .github/workflows/Publish_NIMS.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml index 9ae8b1ee8..51f15b13f 100644 --- a/.github/workflows/Publish_NIMS.yml +++ b/.github/workflows/Publish_NIMS.yml @@ -61,12 +61,14 @@ jobs: git config --local user.name "GitHub Action" git add . git commit -m "Promote NIMS and NIMG package version" -a + echo "HAS_VERSION_CHANGES=1" else + echo "HAS_VERSION_CHANGES=0" echo "No changes. Not committing version changes."; fi - name: Push changes to the appropriate branch - if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} + if: steps.generator.outputs.HAS_VERSION_CHANGES && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) uses: CasperWA/push-protected@v2 with: token: ${{ secrets.ADMIN_PAT }} From f892a0eb1b0592e4d807e4b5083edd87c4d3059d Mon Sep 17 00:00:00 2001 From: Joel Dixon Date: Thu, 11 Jan 2024 16:45:22 -0600 Subject: [PATCH 3/5] Use GITHUB_OUTPUT for check --- .github/workflows/Publish_NIMS.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml index 51f15b13f..4572b6087 100644 --- a/.github/workflows/Publish_NIMS.yml +++ b/.github/workflows/Publish_NIMS.yml @@ -54,21 +54,19 @@ jobs: working-directory: ./ni_measurementlink_generator - name: Commit file changes + id: commit if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} run: | + echo "version_changed=0" >> $GITHUB_OUTPUT if [ -n "$(git status --porcelain)" ]; then git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add . git commit -m "Promote NIMS and NIMG package version" -a - echo "HAS_VERSION_CHANGES=1" - else - echo "HAS_VERSION_CHANGES=0" - echo "No changes. Not committing version changes."; - fi + echo "version_changed=1" >> $GITHUB_OUTPUT - name: Push changes to the appropriate branch - if: steps.generator.outputs.HAS_VERSION_CHANGES && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) + if: ${{ steps.commit.outputs.version_changed==1 }} && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) uses: CasperWA/push-protected@v2 with: token: ${{ secrets.ADMIN_PAT }} From 3aa4e9f43bbb388b5a7c32d0d35253458433d30d Mon Sep 17 00:00:00 2001 From: Joel Dixon Date: Thu, 11 Jan 2024 16:47:45 -0600 Subject: [PATCH 4/5] Move brackets outside whole expression --- .github/workflows/Publish_NIMS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml index 4572b6087..9d463ee31 100644 --- a/.github/workflows/Publish_NIMS.yml +++ b/.github/workflows/Publish_NIMS.yml @@ -66,7 +66,7 @@ jobs: echo "version_changed=1" >> $GITHUB_OUTPUT - name: Push changes to the appropriate branch - if: ${{ steps.commit.outputs.version_changed==1 }} && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) + if: ${{ steps.commit.outputs.version_changed==1 && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) }} uses: CasperWA/push-protected@v2 with: token: ${{ secrets.ADMIN_PAT }} From f978b629c733dc8d8a34263c87244b38f62cda67 Mon Sep 17 00:00:00 2001 From: Joel Dixon Date: Fri, 12 Jan 2024 09:25:33 -0600 Subject: [PATCH 5/5] Add a fi statement. Use a boolean variable --- .github/workflows/Publish_NIMS.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml index 9d463ee31..4e724d6a5 100644 --- a/.github/workflows/Publish_NIMS.yml +++ b/.github/workflows/Publish_NIMS.yml @@ -57,16 +57,17 @@ jobs: id: commit if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} run: | - echo "version_changed=0" >> $GITHUB_OUTPUT + echo "version_changed=false" >> $GITHUB_OUTPUT if [ -n "$(git status --porcelain)" ]; then git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add . git commit -m "Promote NIMS and NIMG package version" -a - echo "version_changed=1" >> $GITHUB_OUTPUT + echo "version_changed=true" >> $GITHUB_OUTPUT + fi - name: Push changes to the appropriate branch - if: ${{ steps.commit.outputs.version_changed==1 && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) }} + if: ${{ steps.commit.outputs.version_changed && (startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/')) }} uses: CasperWA/push-protected@v2 with: token: ${{ secrets.ADMIN_PAT }}