From 7dac50c14a77632893411e7fd8988042441a2933 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 14:25:20 -0500 Subject: [PATCH 1/7] update to use bash commands instead of outside actions --- action.yml | 95 +++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/action.yml b/action.yml index c1f6939..75a77ed 100644 --- a/action.yml +++ b/action.yml @@ -35,8 +35,14 @@ inputs: GITHUB_TOKEN: description: Token to use to commit the file. If you use the GITHUB_TOKEN this commit will not retrigger workflows. Use a PAT to cause the commit to re-trigger workflows. required: true - commit_author: # author expected in the format "Lorem J. Ipsum " - description: Author of the commit for the changelog file + commit_author_name: + description: Name of the author of the commit + required: true + commit_author_email: + description: Email of the author of the commit + required: true + label: + description: GitHub label to trigger off of required: true commit_message: description: Message to put on commit of new changelog file @@ -44,10 +50,8 @@ inputs: default: "Add automated changelog yaml from template" changie_kind: description: Type of changelog file # TODO: how does changie define this? - required: true - label: - description: GitHub label to trigger off of - required: true + required: false + default: "Dependencies" custom_changelog_string: # is this the right way? could it be templated? start here and iterate. description: The multi-line string containing the expected contents of the custom fields for a changelog entry. required: false @@ -56,47 +60,44 @@ runs: using: "composite" steps: - - name: Check if changelog file exists already - # if there's already a changelog entry, don't add another one! - # https://github.com/marketplace/actions/paths-changes-filter - # For each filter, it sets output variable named by the filter to the text: - # 'true' - if any of changed files matches any of filter rules - # 'false' - if none of changed files matches any of filter rules - # also, returns: - # `changes` - JSON array with names of all filters matching any of the changed files - uses: dorny/paths-filter@v2 - id: changelog_check - with: - token: ${{ inputs.GITHUB_TOKEN }} - filters: | - exists: - - added: '.changes/unreleased/**.yaml' + - name: Check if changelog file exists already + # if there's already a changelog entry, don't add another one! + shell: bash + id: changelog_check + run: | + declare RESULT=$(git diff --name-only ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }}) + if echo $RESULT | grep '.changes/unreleased/**.yaml'; then + echo "::set-output name=exists::true" + echo "Changelog already exists for this PR, skip creating a new one" + else + echo "::set-output name=exists::false" + fi - - name: Checkout Branch - if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label - uses: actions/checkout@v3 - with: - # specifying the ref avoids checking out the repository in a detached state - ref: ${{ github.event.pull_request.head.ref }} - token: ${{ inputs.GITHUB_TOKEN }} + - name: Checkout Branch + if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label + uses: actions/checkout@v3 + with: + # specifying the ref avoids checking out the repository in a detached state + ref: ${{ github.event.pull_request.head.ref }} + token: ${{ inputs.GITHUB_TOKEN }} - - name: Create file from template - if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label - shell: bash - run: | - FILEPATH=.changes/unreleased/Dependencies-$(date +%Y%m%d-%H%M%S).yaml - echo kind: "${{ inputs.changie_kind }}" > $FILEPATH - echo 'body: "${{ github.event.pull_request.title }}"' >> $FILEPATH - echo time: $(date +%Y-%m-%dT%H:%M:%S.00000Z) >> $FILEPATH - echo "${{ inputs.custom_changelog_string }}" >> $FILEPATH + - name: Create file from template + if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label + shell: bash + run: | + FILEPATH=.changes/unreleased/${{ inputes.changie_kind }}-$(date +%Y%m%d-%H%M%S).yaml + echo kind: "${{ inputs.changie_kind }}" > $FILEPATH + echo 'body: "${{ github.event.pull_request.title }}"' >> $FILEPATH + echo time: $(date +%Y-%m-%dT%H:%M:%S.00000Z) >> $FILEPATH + echo "${{ inputs.custom_changelog_string }}" >> $FILEPATH - - name: Commit Changelog File - if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label - uses: gr2m/create-or-update-pull-request-action@v1 - env: - GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} - with: - branch: ${{ github.event.pull_request.head.ref }} - # author expected in the format "Lorem J. Ipsum " - author: ${{ inputs.commit_author }} - commit-message: ${{ inputs.commit_message }} + - name: Commit & Push changes + if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label + shell: bash + run: | + git config user.name ${{ inputs.commit_author_name }} + git config user.email ${{ inputs.commit_author_email }} + git pull + git add . + git commit -m ${{ inputs.commit_message }} + git push From da8bca77fdcdd3e3053a16743c2085d0bf26eab6 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 14:30:49 -0500 Subject: [PATCH 2/7] fix comments --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 75a77ed..2b8014a 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ # **what?** -# Add a changelog yaml file per changie expectation when a bot creates a PR. The new yaml file +# Add a changelog yaml file when a bot creates a PR. The new yaml file # will be created if none already exists on the PR when the PR has a specifed label. Once created, # it will be committed by a specified bot and commit will be pushed to the PR. # @@ -14,9 +14,9 @@ # # Assumptions # 1. You're using changie -# 2. Your changelogs live in the default `.changes. path, nothing custom +# 2. Your changelogs live in the default `.changes`. path, nothing custom # 3. This action is called in the context of a PR -# 4. Not changelog yaml file already exists on this PR +# 4. No changelog yaml file already exists on this PR # 5. This PR already exists and you just need to add a commit with the changelog to it # # A note on tokens: From 78a876e12a7c069fb9d8222a54471b4897384e07 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 14:51:40 -0500 Subject: [PATCH 3/7] fix typo --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2b8014a..83c2ff9 100644 --- a/action.yml +++ b/action.yml @@ -85,7 +85,7 @@ runs: if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label shell: bash run: | - FILEPATH=.changes/unreleased/${{ inputes.changie_kind }}-$(date +%Y%m%d-%H%M%S).yaml + FILEPATH=.changes/unreleased/${{ inputs.changie_kind }}-$(date +%Y%m%d-%H%M%S).yaml echo kind: "${{ inputs.changie_kind }}" > $FILEPATH echo 'body: "${{ github.event.pull_request.title }}"' >> $FILEPATH echo time: $(date +%Y-%m-%dT%H:%M:%S.00000Z) >> $FILEPATH From 7df36d8f12030aa0b8fad190059668df26bde3d5 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 14:54:06 -0500 Subject: [PATCH 4/7] add quotes around user.name --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 83c2ff9..4e7a7fa 100644 --- a/action.yml +++ b/action.yml @@ -95,7 +95,7 @@ runs: if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label shell: bash run: | - git config user.name ${{ inputs.commit_author_name }} + git config user.name "${{ inputs.commit_author_name }}" git config user.email ${{ inputs.commit_author_email }} git pull git add . From d7efac5288f408496559a3d959467b61643fbe7b Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 14:57:20 -0500 Subject: [PATCH 5/7] add single quotes --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 4e7a7fa..88e7ad7 100644 --- a/action.yml +++ b/action.yml @@ -95,8 +95,8 @@ runs: if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label shell: bash run: | - git config user.name "${{ inputs.commit_author_name }}" - git config user.email ${{ inputs.commit_author_email }} + git config user.name '${{ inputs.commit_author_name }}' + git config user.email '${{ inputs.commit_author_email }}' git pull git add . git commit -m ${{ inputs.commit_message }} From 7bb2e3e533caea622e215a686942f09a3ce205a1 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 15:01:18 -0500 Subject: [PATCH 6/7] add status check --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 88e7ad7..67b6245 100644 --- a/action.yml +++ b/action.yml @@ -95,6 +95,7 @@ runs: if: steps.changelog_check.outputs.exists == 'false' && github.event.label.name == inputs.label shell: bash run: | + git status git config user.name '${{ inputs.commit_author_name }}' git config user.email '${{ inputs.commit_author_email }}' git pull From 1e62d053a1410bbb3542ebdbf36e85b44bb1bf20 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Sun, 10 Jul 2022 15:02:51 -0500 Subject: [PATCH 7/7] add quotes to commit message --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 67b6245..1e8e4dc 100644 --- a/action.yml +++ b/action.yml @@ -100,5 +100,5 @@ runs: git config user.email '${{ inputs.commit_author_email }}' git pull git add . - git commit -m ${{ inputs.commit_message }} + git commit -m "${{ inputs.commit_message }}" git push