From 3769f0e3fdac73ee0df09b11d0a958f30a831e46 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 3 Oct 2024 14:15:38 -0600 Subject: [PATCH 01/19] Adding artifact --- .github/workflows/test-post-artifact.yml | 74 +++++++++++++ README.md | 28 ++--- post-artifact/README.md | 93 +++++++++++++++++ post-artifact/action.yml | 126 +++++++++++++++++++++++ post-artifact/scripts/compose-msg.py | 39 +++++++ post-artifact/scripts/find-comment.py | 62 +++++++++++ post-artifact/scripts/id-artifact.py | 41 ++++++++ 7 files changed, 444 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/test-post-artifact.yml create mode 100644 post-artifact/README.md create mode 100644 post-artifact/action.yml create mode 100644 post-artifact/scripts/compose-msg.py create mode 100644 post-artifact/scripts/find-comment.py create mode 100644 post-artifact/scripts/id-artifact.py diff --git a/.github/workflows/test-post-artifact.yml b/.github/workflows/test-post-artifact.yml new file mode 100644 index 0000000..c586ff6 --- /dev/null +++ b/.github/workflows/test-post-artifact.yml @@ -0,0 +1,74 @@ +name: Test PR post artifact + +on: + pull_request: + branches: [main] + pull_request_target: + paths: + - '.github/workflows/test-post-artifact.yml' + - 'post-artifact/action.yml' + push: + branches: [main] + paths: + - '.github/workflows/test-post-artifact.yml' + - 'post-artifact/action.yml' + +jobs: + build-artifact-container: + runs-on: ubuntu-latest + container: rocker/tidyverse:4.4.0 + + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/checkout@v4 + name: Checkout code + + - uses: actions/upload-artifact@v4 + name: Upload artifact + with: + path: './README.md' + name: 'readme-rocker' + + - name: Install gh + run: | + apt update + apt install -y --no-install-recommends gh + + - name: Post the artifact + uses: ./post-artifact + with: + artifact-name: 'readme-rocker' + python: 'python3' + gh-token: ${{ secrets.GITHUB_TOKEN }} + + build-artifact: + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} + + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/checkout@v4 + name: Checkout code + + - uses: actions/upload-artifact@v4 + name: Upload artifact + with: + path: './README.md' + name: ${{ format('readme-{0}', matrix.os) }} + + - name: Post the artifact + uses: ./post-artifact + with: + artifact-name: ${{ format('readme-{0}', matrix.os) }} + gh-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index a3cae32..3174c5c 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,15 @@ -# CDCgov GitHub Organization Open Source Project Template +## CFA Actions -**Template for clearance: This project serves as a template to aid projects in starting up and moving through clearance procedures. To start, create a new repository and implement the required [open practices](open_practices.md), train on and agree to adhere to the organization's [rules of behavior](rules_of_behavior.md), and [send a request through the create repo form](https://forms.office.com/Pages/ResponsePage.aspx?id=aQjnnNtg_USr6NJ2cHf8j44WSiOI6uNOvdWse4I-C2NUNk43NzMwODJTRzA4NFpCUk1RRU83RTFNVi4u) using language from this template as a Guide.** +> [!CAUTION] +> This product is still in development. +> Note the product is still flagged as in development, though the authors plan on using it for production work in the coming weeks. +> All development is in public as part of the Center for Forecasting and Outbreak Analytics' goals around open development. +> Questions and suggestions are welcome through GitHub issues or a PR. +> -**General disclaimer** This repository was created for use by CDC programs to collaborate on public health related projects in support of the [CDC mission](https://www.cdc.gov/about/organization/mission.htm). GitHub is not hosted by the CDC, but is a third party website used by CDC and its partners to share information and collaborate on software. CDC use of GitHub does not imply an endorsement of any one particular service, product, or enterprise. +This repo contains personalized actions designed by CDC's CFA team. Please use with caution as these actions are not officially supported by GitHub. -## Access Request, Repo Creation Request - -* [CDC GitHub Open Project Request Form](https://forms.office.com/Pages/ResponsePage.aspx?id=aQjnnNtg_USr6NJ2cHf8j44WSiOI6uNOvdWse4I-C2NUNk43NzMwODJTRzA4NFpCUk1RRU83RTFNVi4u) _[Requires a CDC Office365 login, if you do not have a CDC Office365 please ask a friend who does to submit the request on your behalf. If you're looking for access to the CDCEnt private organization, please use the [GitHub Enterprise Cloud Access Request form](https://forms.office.com/Pages/ResponsePage.aspx?id=aQjnnNtg_USr6NJ2cHf8j44WSiOI6uNOvdWse4I-C2NUQjVJVDlKS1c0SlhQSUxLNVBaOEZCNUczVS4u).]_ - -## Related documents - -* [Open Practices](open_practices.md) -* [Rules of Behavior](rules_of_behavior.md) -* [Thanks and Acknowledgements](thanks.md) -* [Disclaimer](DISCLAIMER.md) -* [Contribution Notice](CONTRIBUTING.md) -* [Code of Conduct](code-of-conduct.md) - -## Overview - -Describe the purpose of your project. Add additional sections as necessary to help collaborators and potential collaborators understand and use your project. +- [post-artifact](./post-artifact): Post an artifact as a comment in a PR. Useful when you need to easily access a built element during a workflow such as a website, a report, etc. ## Public Domain Standard Notice This repository constitutes a work of the United States Government and is not diff --git a/post-artifact/README.md b/post-artifact/README.md new file mode 100644 index 0000000..e7e3a91 --- /dev/null +++ b/post-artifact/README.md @@ -0,0 +1,93 @@ +# Post artifact as a comment [![Test PR post artifact](https://github.com/CDCgov/cfa-actions/actions/workflows/test-post-artifact.yml/badge.svg)](https://github.com/CDCgov/cfa-actions/actions/workflows/test-post-artifact.yml) + +## Inputs + +| Field | Description | Required | Default | +|---------------|-----------------------------------------------------------------------------------------------------------------------------------------|----------|----------------| +| `gh-token` | The GitHub token to use for the API calls. | true | - | +| `artifact-name` | Artifact name as in the `actions/upload-artifact` step. | false | `artifact` | +| `message` | Message template to be posted in the PR. The message should include a placeholder for { artifact-url }. Optionally, the { artifact-name } placeholder can be used to include the artifact name in the message. | false | `'Thank you for your contribution ${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!'` | +| `python` | The path to the Python executable. | false | `'python'` | + +This action only runs in PRs and requires the `pull-requests: write` permission. + +## Example: Post artifact created within a job + +Here are the contents of a job that (i) uploads an artifact using `actions/upload-artifact` and (ii) posts the artifact as a comment using this action. The action requires the runner to have: `python` and `gh cli` installed. + + +```yaml + # Required permissions + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/checkout@v4 + name: Checkout code + + # Uploading an artifact with name 'readme' + - uses: actions/upload-artifact@v4 + name: Upload artifact + with: + path: './README.md' + name: readme + + # Post the artifact pulling the id from the `readme` step. + - name: Post the artifact + uses: CDCgov/cfa-actions/post-artifact@main + with: + artifact-name: readme + gh-token: ${{ secrets.GITHUB_TOKEN }} + message: 'Thank you for your contribution ${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!' +``` + +For a live example, see [../.github/workflows/test-post-artifact.yml](../.github/workflows/test-post-artifact.yml). + +## Example: Post an artifact created in a previous job + +When passing between jobs, the artifact id can be passed as an output. Here is an example of how to do it: + +```yaml +jobs: + + build: + + runs-on: ubuntu-latest + + # Expose the artifact id as an output + outputs: + artifact-id: ${{ steps.upload.outputs.artifact-id }} + + steps: + - uses: actions/checkout@v4 + name: Checkout code + + # Uploading an artifact with id 'readme' + - uses: actions/upload-artifact@v4 + name: Upload artifact + with: + path: './README.md' + name: readme + + post: + runs-on: ubuntu-latest + + # This job depends on the `build` job + needs: build + + # Required permissions + permissions: + contents: read + pull-requests: write + + steps: + # Post the artifact pulling the id from the `readme` step. + # The msg will refer to the arfitact as 'README file'. + - name: Post the artifact + uses: CDCgov/cfa-actions/post-artifact@main + with: + artifact-name: readme + gh-token: ${{ secrets.GITHUB_TOKEN }} + +``` diff --git a/post-artifact/action.yml b/post-artifact/action.yml new file mode 100644 index 0000000..f9aa3fa --- /dev/null +++ b/post-artifact/action.yml @@ -0,0 +1,126 @@ +name: post-artifact +description: | + Creates a post in the PR linking to an artifact for easy access. + Subsequent runs will update the comment. +inputs: + artifact-name: + description: | + Name of the artifact to upload (should match the one passed to + `actions/upload-artifact`). + required: false + default: 'artifact' + message: + description: | + Message template to be posted in the PR. The message should include + a placeholder for { artifact-url }. Optionally, the { artifact-name } + placeholder can be used to include the artifact name in the message. + required: false + default: 'Thank you for your contribution @${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!' + python: + description: | + The path to the Python executable. This input is optional and + defaults to 'python'. + required: false + default: 'python' + gh-token: + description: | + The GitHub token to use for the API calls. + required: true +runs: + using: 'composite' + + steps: + + # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts + - name: List artifacts + if: ${{ github.event_name == 'pull_request' }} + run: | + gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts > _artifacts-${{ github.sha }}.json + shell: bash + env: + GH_TOKEN: ${{ inputs.gh-token }} + + - name: Id artifact + if: ${{ github.event_name == 'pull_request' }} + run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/id-artifact.py + shell: bash + env: + ARTIFACT_NAME: ${{ inputs.artifact-name }} + SHA: ${{ github.sha }} + + - name: Get artifact id + if: ${{ github.event_name == 'pull_request' }} + id: artifact-id + run: | + echo "VALUE=$(cat '${{ github.sha }}_artifact_id')" >> $GITHUB_OUTPUT + shell: bash + + - name: Compose message + if: ${{ github.event_name == 'pull_request' }} + run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/compose-msg.py + shell: bash + env: + ARTIFACT_NAME: ${{ inputs.artifact-name }} + MESSAGE: ${{ inputs.message }} + SERVER_URL: ${{ github.server_url }} + REPOSITORY: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + ARTIFACT_ID: ${{ steps.artifact-id.outputs.VALUE }} + SHA: ${{ github.sha }} + + - name: Get the event + if: ${{ github.event_name == 'pull_request' }} + run: | + gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/issues/${{ github.event.number }}/comments > _events-${{ github.sha }}.json + shell: bash + env: + GH_TOKEN: ${{ inputs.gh-token }} + + - name: Find the comment + if: ${{ github.event_name == 'pull_request' }} + run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/find-comment.py + shell: bash + env: + SHA: ${{ github.sha }} + ARTIFACT_NAME: ${{ inputs.artifact-name }} + + - name: Putting the contents of _msg.txt into an environment var + if: ${{ github.event_name == 'pull_request' }} + id: set-env + run: | + echo "MSG=$(cat msg-${{ github.sha }}.txt)" >> $GITHUB_OUTPUT + echo "ID=$(cat _ID-${{ github.sha }})" >> $GITHUB_OUTPUT + echo "FOUND=$(cat _ID-${{ github.sha }}_found)" >> $GITHUB_OUTPUT + shell: bash + + # See: + # https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#update-an-issue-comment + - name: Add comment + if: ${{ github.event_name == 'pull_request' && steps.set-env.outputs.FOUND == 'false' }} + run: | + echo "No comment from github-bot found, adding a new one." + gh pr comment -R ${{ github.repository }} \ + ${{ github.event.number }} -b "${{ steps.set-env.outputs.MSG }}" + shell: bash + env: + GH_TOKEN: ${{ inputs.gh-token }} + + - name: Update comment + if: ${{ github.event_name == 'pull_request' && steps.set-env.outputs.FOUND == 'true' }} + run: | + echo "Editing original comment id: ${{ steps.set-env.outputs.ID }}." + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + repos/${{ github.repository }}/issues/comments/${{ steps.set-env.outputs.ID }} \ + -f "body=${{ steps.set-env.outputs.MSG }}" + shell: bash + env: + GH_TOKEN: ${{ inputs.gh-token }} diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py new file mode 100644 index 0000000..e65f816 --- /dev/null +++ b/post-artifact/scripts/compose-msg.py @@ -0,0 +1,39 @@ +import re + +# Retrieving environment variables +import os +import sys + +ARTIFACT_NAME = os.environ.get('ARTIFACT_NAME') +MESSAGE = os.environ.get('MESSAGE') +SERVER_URL = os.environ.get('SERVER_URL') +REPOSITORY = os.environ.get('REPOSITORY') +RUN_ID = os.environ.get('RUN_ID') +ARTIFACT_ID = os.environ.get('ARTIFACT_ID') +SHA = os.environ.get('SHA') + +msg = "[]("+ re.sub(r'\s+', '_', ARTIFACT_NAME)+")" +msg = msg + MESSAGE + +updated = re.sub( + r'{ artifact-name }', + ARTIFACT_NAME, + msg + ) + +if not re.search(r'{ artifact-url }', updated): + print( + "The message template must include the placeholder " \ + "{ artifact-url }." + ) + sys.exit(1) + +updated = re.sub( + r'{ artifact-url }', + SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID + \ + '/artifacts/' + ARTIFACT_ID, + updated + ) + +with open('msg-' + SHA + '.txt', 'w') as file: + file.write(updated) \ No newline at end of file diff --git a/post-artifact/scripts/find-comment.py b/post-artifact/scripts/find-comment.py new file mode 100644 index 0000000..19c83aa --- /dev/null +++ b/post-artifact/scripts/find-comment.py @@ -0,0 +1,62 @@ +import json +import re +import os + +# Retrieving environment variables +ARTIFACT_NAME = os.environ.get('ARTIFACT_NAME') +SHA = os.environ.get('SHA') + +def main(json_comments) -> str: + + # Open the JSON file and load its contents into a Python object + with open(json_comments, 'r') as file: + data = json.load(file) + + if (data == []): + return '' + + matching_msg = re.escape( + "[](" + re.sub(r'\s+', '_', ARTIFACT_NAME)+")" + ) + + # Now you can work with the 'data' object + for i in range(len(data)): + + body = data[i].get('body') + auth = data[i].get('user').get('login') + url = data[i].get('url') + + if not url: + continue + + if not auth: + continue + + if not body: + continue + + match = re.search(r'\d+$', url) + + if not match: + continue + + id = match.group() + + # Regex match to the body of the comment looking + # for the expression "Thank you for your contribution" + # if found, print the author and the body of the comment + if (re.search(matching_msg, body)) and (re.match(r'^github-actions\[bot\]', auth)): + return id + + return '' + +id = main('_events-' + SHA + '.json') +fn = '_ID-' + SHA +with (open(fn, 'w')) as file: + file.write(id) + +with (open(fn+'_found', 'w')) as file: + if id == '': + file.write('false') + else: + file.write('true') \ No newline at end of file diff --git a/post-artifact/scripts/id-artifact.py b/post-artifact/scripts/id-artifact.py new file mode 100644 index 0000000..4bf00d1 --- /dev/null +++ b/post-artifact/scripts/id-artifact.py @@ -0,0 +1,41 @@ +import re +import json +import sys +import os + +# Retrieving environment variables +ARTIFACT_NAME = os.environ.get('ARTIFACT_NAME') +SHA = os.environ.get('SHA') + +def find_artifact() -> str: + fn = '_artifacts-' + SHA + '.json' + with open(fn, 'r') as file: + data = json.load(file) + + artifacts = data.get('artifacts') + + for i in range(len(artifacts)): + + print(f"Artifact: {artifacts[i]}") + + name = artifacts[i].get('name') + id = artifacts[i].get('id') + + if not name: + continue + + if not id: + continue + + if ARTIFACT_NAME == name: + return str(id) + return '' + +id = find_artifact() + +if id == '': + print(f"Artifact { ARTIFACT_NAME } not found.") + sys.exit(1) + +with open(SHA + '_artifact_id', 'w') as file: + file.write(id) \ No newline at end of file From 686ddbebc71f8529d7e86dc5fc629a156f8ae13a Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:14:25 -0600 Subject: [PATCH 02/19] Adding expiration date and how to re-run --- post-artifact/action.yml | 10 ++++++---- post-artifact/scripts/compose-msg.py | 5 +++++ .../scripts/{id-artifact.py => fetch-artifact-meta.py} | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) rename post-artifact/scripts/{id-artifact.py => fetch-artifact-meta.py} (83%) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index f9aa3fa..a66f3b7 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -45,7 +45,7 @@ runs: - name: Id artifact if: ${{ github.event_name == 'pull_request' }} - run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/id-artifact.py + run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/fetch-artifact-meta.py shell: bash env: ARTIFACT_NAME: ${{ inputs.artifact-name }} @@ -53,9 +53,10 @@ runs: - name: Get artifact id if: ${{ github.event_name == 'pull_request' }} - id: artifact-id + id: artifact-meta run: | - echo "VALUE=$(cat '${{ github.sha }}_artifact_id')" >> $GITHUB_OUTPUT + echo "id=$(cat '${{ github.sha }}_artifact_id')" >> $GITHUB_OUTPUT + echo "expires_at=$(cat '${{ github.sha }}_artifact_expires_at')" >> $GITHUB_OUTPUT shell: bash - name: Compose message @@ -68,8 +69,9 @@ runs: SERVER_URL: ${{ github.server_url }} REPOSITORY: ${{ github.repository }} RUN_ID: ${{ github.run_id }} - ARTIFACT_ID: ${{ steps.artifact-id.outputs.VALUE }} + ARTIFACT_ID: ${{ steps.artifact-meta.outputs.id }} SHA: ${{ github.sha }} + EXP_DATE: ${{ steps.artifact-meta.outputs.expires_at }} - name: Get the event if: ${{ github.event_name == 'pull_request' }} diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index e65f816..ad6df3d 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -11,6 +11,7 @@ RUN_ID = os.environ.get('RUN_ID') ARTIFACT_ID = os.environ.get('ARTIFACT_ID') SHA = os.environ.get('SHA') +EXP_DATE = os.environ.get('EXP_DATE') msg = "[]("+ re.sub(r'\s+', '_', ARTIFACT_NAME)+")" msg = msg + MESSAGE @@ -35,5 +36,9 @@ updated ) +run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID +updated = updated + + f'
(The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow here)' + with open('msg-' + SHA + '.txt', 'w') as file: file.write(updated) \ No newline at end of file diff --git a/post-artifact/scripts/id-artifact.py b/post-artifact/scripts/fetch-artifact-meta.py similarity index 83% rename from post-artifact/scripts/id-artifact.py rename to post-artifact/scripts/fetch-artifact-meta.py index 4bf00d1..0a7ed41 100644 --- a/post-artifact/scripts/id-artifact.py +++ b/post-artifact/scripts/fetch-artifact-meta.py @@ -20,6 +20,7 @@ def find_artifact() -> str: name = artifacts[i].get('name') id = artifacts[i].get('id') + expires_at = artifacts[i].get('expires_at') if not name: continue @@ -38,4 +39,7 @@ def find_artifact() -> str: sys.exit(1) with open(SHA + '_artifact_id', 'w') as file: - file.write(id) \ No newline at end of file + file.write(id) + +with open(SHA + '_artifact_expires_at', 'w') as file: + file.write(expires_at) \ No newline at end of file From 9b0347ceb747c6c7d66dbcdd214b2e153eaf55fe Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:17:01 -0600 Subject: [PATCH 03/19] Fixing my python --- post-artifact/scripts/fetch-artifact-meta.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/post-artifact/scripts/fetch-artifact-meta.py b/post-artifact/scripts/fetch-artifact-meta.py index 0a7ed41..e0c4fc3 100644 --- a/post-artifact/scripts/fetch-artifact-meta.py +++ b/post-artifact/scripts/fetch-artifact-meta.py @@ -7,7 +7,7 @@ ARTIFACT_NAME = os.environ.get('ARTIFACT_NAME') SHA = os.environ.get('SHA') -def find_artifact() -> str: +def find_artifact() -> dict: fn = '_artifacts-' + SHA + '.json' with open(fn, 'r') as file: data = json.load(file) @@ -29,17 +29,17 @@ def find_artifact() -> str: continue if ARTIFACT_NAME == name: - return str(id) + return dict(id=str(id), expires_at=expires_at) return '' -id = find_artifact() +meta = find_artifact() -if id == '': +if meta.id == '': print(f"Artifact { ARTIFACT_NAME } not found.") sys.exit(1) with open(SHA + '_artifact_id', 'w') as file: - file.write(id) + file.write(meta.id) with open(SHA + '_artifact_expires_at', 'w') as file: - file.write(expires_at) \ No newline at end of file + file.write(meta.expires_at) \ No newline at end of file From 8500040951cfbcc32ca9772233d0d912788d8b06 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:18:41 -0600 Subject: [PATCH 04/19] Fixing my python --- post-artifact/scripts/fetch-artifact-meta.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/post-artifact/scripts/fetch-artifact-meta.py b/post-artifact/scripts/fetch-artifact-meta.py index e0c4fc3..6b77774 100644 --- a/post-artifact/scripts/fetch-artifact-meta.py +++ b/post-artifact/scripts/fetch-artifact-meta.py @@ -34,12 +34,12 @@ def find_artifact() -> dict: meta = find_artifact() -if meta.id == '': +if meta.get('id') == '': print(f"Artifact { ARTIFACT_NAME } not found.") sys.exit(1) with open(SHA + '_artifact_id', 'w') as file: - file.write(meta.id) + file.write(meta..get('id')) with open(SHA + '_artifact_expires_at', 'w') as file: - file.write(meta.expires_at) \ No newline at end of file + file.write(meta.get('expires_at')) \ No newline at end of file From 4a84b9e0b530e76609e6427915275125a98ce217 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:19:19 -0600 Subject: [PATCH 05/19] Fixing my python v3 --- post-artifact/scripts/fetch-artifact-meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-artifact/scripts/fetch-artifact-meta.py b/post-artifact/scripts/fetch-artifact-meta.py index 6b77774..ecddadd 100644 --- a/post-artifact/scripts/fetch-artifact-meta.py +++ b/post-artifact/scripts/fetch-artifact-meta.py @@ -39,7 +39,7 @@ def find_artifact() -> dict: sys.exit(1) with open(SHA + '_artifact_id', 'w') as file: - file.write(meta..get('id')) + file.write(meta.get('id')) with open(SHA + '_artifact_expires_at', 'w') as file: file.write(meta.get('expires_at')) \ No newline at end of file From 26f77e231f60de0929f539ceadb34964cc24b0c0 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:20:16 -0600 Subject: [PATCH 06/19] Fixing my python v4 --- post-artifact/scripts/compose-msg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index ad6df3d..90d1549 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -37,7 +37,7 @@ ) run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID -updated = updated + +updated = updated + \ f'
(The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow here)' with open('msg-' + SHA + '.txt', 'w') as file: From b9cbbc3a6c8c9f41762950f7bce458d64a386bec Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:26:26 -0600 Subject: [PATCH 07/19] Reformating default message --- post-artifact/scripts/compose-msg.py | 4 ++-- post-artifact/scripts/find-comment.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index 90d1549..ab9126f 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -13,7 +13,7 @@ SHA = os.environ.get('SHA') EXP_DATE = os.environ.get('EXP_DATE') -msg = "[]("+ re.sub(r'\s+', '_', ARTIFACT_NAME)+")" +msg = "" msg = msg + MESSAGE updated = re.sub( @@ -38,7 +38,7 @@ run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID updated = updated + \ - f'
(The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow here)' + f'\n\n> ![IMPORTANT]\n> The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' with open('msg-' + SHA + '.txt', 'w') as file: file.write(updated) \ No newline at end of file diff --git a/post-artifact/scripts/find-comment.py b/post-artifact/scripts/find-comment.py index 19c83aa..a9e8680 100644 --- a/post-artifact/scripts/find-comment.py +++ b/post-artifact/scripts/find-comment.py @@ -16,7 +16,7 @@ def main(json_comments) -> str: return '' matching_msg = re.escape( - "[](" + re.sub(r'\s+', '_', ARTIFACT_NAME)+")" + "" ) # Now you can work with the 'data' object From 0054875365ea13adfe1a45c9de832b672e60c7ec Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:32:08 -0600 Subject: [PATCH 08/19] Reading the msg file directly --- post-artifact/action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index a66f3b7..4c980d9 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -96,7 +96,6 @@ runs: if: ${{ github.event_name == 'pull_request' }} id: set-env run: | - echo "MSG=$(cat msg-${{ github.sha }}.txt)" >> $GITHUB_OUTPUT echo "ID=$(cat _ID-${{ github.sha }})" >> $GITHUB_OUTPUT echo "FOUND=$(cat _ID-${{ github.sha }}_found)" >> $GITHUB_OUTPUT shell: bash @@ -108,7 +107,7 @@ runs: run: | echo "No comment from github-bot found, adding a new one." gh pr comment -R ${{ github.repository }} \ - ${{ github.event.number }} -b "${{ steps.set-env.outputs.MSG }}" + ${{ github.event.number }} -F msg-${{ github.sha }}.txt shell: bash env: GH_TOKEN: ${{ inputs.gh-token }} @@ -122,7 +121,7 @@ runs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ repos/${{ github.repository }}/issues/comments/${{ steps.set-env.outputs.ID }} \ - -f "body=${{ steps.set-env.outputs.MSG }}" + -F 'body=@msg-${{ github.sha }}.txt' shell: bash env: GH_TOKEN: ${{ inputs.gh-token }} From 1d60cd0eeeceb7b5bdc908c8d6978668f3fb8fb0 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:36:12 -0600 Subject: [PATCH 09/19] Updating message (minor bug) --- post-artifact/scripts/compose-msg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index ab9126f..785d038 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -38,7 +38,7 @@ run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID updated = updated + \ - f'\n\n> ![IMPORTANT]\n> The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' + f'\n\n> [!IMPORTANT]\n> The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' with open('msg-' + SHA + '.txt', 'w') as file: file.write(updated) \ No newline at end of file From c28faf69e9711951a84ed500cae860164f771d14 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:42:56 -0600 Subject: [PATCH 10/19] Correcting message --- post-artifact/scripts/compose-msg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index 785d038..9cd977a 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -13,7 +13,7 @@ SHA = os.environ.get('SHA') EXP_DATE = os.environ.get('EXP_DATE') -msg = "" +msg = "\n" msg = msg + MESSAGE updated = re.sub( @@ -38,7 +38,7 @@ run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID updated = updated + \ - f'\n\n> [!IMPORTANT]\n> The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' + f'\nThe artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' with open('msg-' + SHA + '.txt', 'w') as file: file.write(updated) \ No newline at end of file From 4b3a1c81e177a878de49b13988d4c248063b6ff9 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Fri, 4 Oct 2024 10:51:02 -0600 Subject: [PATCH 11/19] Adding parentheses --- post-artifact/scripts/compose-msg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index 9cd977a..9f4275c 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -38,7 +38,7 @@ run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID updated = updated + \ - f'\nThe artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).' + f'\n(The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).)' with open('msg-' + SHA + '.txt', 'w') as file: file.write(updated) \ No newline at end of file From c3d1ddbf0bfa32cf543d820e435ffbd6dff8a37e Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Wed, 9 Oct 2024 11:47:35 -0600 Subject: [PATCH 12/19] Addressing comments by @dylanhmorris --- README.md | 4 ++++ post-artifact/README.md | 2 +- post-artifact/action.yml | 18 ++++++++++-------- post-artifact/scripts/compose-msg.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3174c5c..42b56ee 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ This repo contains personalized actions designed by CDC's CFA team. Please use w - [post-artifact](./post-artifact): Post an artifact as a comment in a PR. Useful when you need to easily access a built element during a workflow such as a website, a report, etc. +> [!NOTE] +**General disclaimer** This repository was created for use by CDC programs to collaborate on public health related projects in support of the [CDC mission](https://www.cdc.gov/about/organization/mission.htm). GitHub is not hosted by the CDC, but is a third party website used by CDC and its partners to share information and collaborate on software. CDC use of GitHub does not imply an endorsement of any one particular service, product, or enterprise. + ## Public Domain Standard Notice This repository constitutes a work of the United States Government and is not subject to domestic copyright protection under 17 USC ยง 105. This repository is in @@ -20,6 +23,7 @@ All contributions to this repository will be released under the CC0 dedication. submitting a pull request you are agreeing to comply with this waiver of copyright interest. + ## License Standard Notice The repository utilizes code licensed under the terms of the Apache Software License and therefore is licensed under ASL v2 or later. diff --git a/post-artifact/README.md b/post-artifact/README.md index e7e3a91..c7a0ac5 100644 --- a/post-artifact/README.md +++ b/post-artifact/README.md @@ -6,7 +6,7 @@ |---------------|-----------------------------------------------------------------------------------------------------------------------------------------|----------|----------------| | `gh-token` | The GitHub token to use for the API calls. | true | - | | `artifact-name` | Artifact name as in the `actions/upload-artifact` step. | false | `artifact` | -| `message` | Message template to be posted in the PR. The message should include a placeholder for { artifact-url }. Optionally, the { artifact-name } placeholder can be used to include the artifact name in the message. | false | `'Thank you for your contribution ${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!'` | +| `message` | Message template to be posted in the PR, as Github-flavored Markdown (GFM). Use the placeholder `{ artifact-url }` to reference the URL of the uploaded artifact, either raw or as GFM formatted link. Use the `{ artifact-name }` placeholder to include the artifact name in the message | false | `'Thank you for your contribution ${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!'` | | `python` | The path to the Python executable. | false | `'python'` | This action only runs in PRs and requires the `pull-requests: write` permission. diff --git a/post-artifact/action.yml b/post-artifact/action.yml index 4c980d9..bc601d0 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -1,19 +1,21 @@ name: post-artifact description: | - Creates a post in the PR linking to an artifact for easy access. - Subsequent runs will update the comment. + Posts a comment on a PR linking to an artifact uploaded in CI for easy access and reference. + Subsequent runs will update the comment with an updated link to the artifact. inputs: artifact-name: description: | - Name of the artifact to upload (should match the one passed to + Name of the artifact to which to link (should match the one passed to `actions/upload-artifact`). required: false default: 'artifact' message: description: | - Message template to be posted in the PR. The message should include - a placeholder for { artifact-url }. Optionally, the { artifact-name } - placeholder can be used to include the artifact name in the message. + Message template to be posted in the PR, as Github-flavored + Markdown (GFM). Use the placeholder `{ artifact-url }` to + reference the URL of the uploaded artifact, either raw + or as GFM formatted link. Use the `{ artifact-name }` + placeholder to include the artifact name in the message. required: false default: 'Thank you for your contribution @${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!' python: @@ -32,7 +34,7 @@ runs: steps: # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts - - name: List artifacts + - name: "Get list of available artifacts and store as .json" if: ${{ github.event_name == 'pull_request' }} run: | gh api \ @@ -43,7 +45,7 @@ runs: env: GH_TOKEN: ${{ inputs.gh-token }} - - name: Id artifact + - name: Fetch metadata for the target artifact if: ${{ github.event_name == 'pull_request' }} run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/fetch-artifact-meta.py shell: bash diff --git a/post-artifact/scripts/compose-msg.py b/post-artifact/scripts/compose-msg.py index 9f4275c..1b15dc1 100644 --- a/post-artifact/scripts/compose-msg.py +++ b/post-artifact/scripts/compose-msg.py @@ -36,7 +36,7 @@ updated ) -run_url = SERVER_URL + '/' + REPOSITORY + '/actions/runs/' + RUN_ID +run_url = f"{SERVER_URL}/{REPOSITORY}/actions/runs/{RUN_ID}" updated = updated + \ f'\n(The artifact expires on {EXP_DATE}. You can re-generate it by re-running the workflow [here]({run_url}).)' From 3878c79dbde25c3e36ac38636c50045e5f6e9642 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Wed, 9 Oct 2024 11:49:40 -0600 Subject: [PATCH 13/19] Moving the General disclaimer down --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42b56ee..e6bf3ff 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ This repo contains personalized actions designed by CDC's CFA team. Please use w - [post-artifact](./post-artifact): Post an artifact as a comment in a PR. Useful when you need to easily access a built element during a workflow such as a website, a report, etc. -> [!NOTE] -**General disclaimer** This repository was created for use by CDC programs to collaborate on public health related projects in support of the [CDC mission](https://www.cdc.gov/about/organization/mission.htm). GitHub is not hosted by the CDC, but is a third party website used by CDC and its partners to share information and collaborate on software. CDC use of GitHub does not imply an endorsement of any one particular service, product, or enterprise. ## Public Domain Standard Notice This repository constitutes a work of the United States Government and is not @@ -67,3 +65,6 @@ published through the [CDC web site](http://www.cdc.gov). ## Additional Standard Notices Please refer to [CDC's Template Repository](https://github.com/CDCgov/template) for more information about [contributing to this repository](https://github.com/CDCgov/template/blob/main/CONTRIBUTING.md), [public domain notices and disclaimers](https://github.com/CDCgov/template/blob/main/DISCLAIMER.md), and [code of conduct](https://github.com/CDCgov/template/blob/main/code-of-conduct.md). + +> [!IMPORTANT] +**General disclaimer** This repository was created for use by CDC programs to collaborate on public health related projects in support of the [CDC mission](https://www.cdc.gov/about/organization/mission.htm). GitHub is not hosted by the CDC, but is a third party website used by CDC and its partners to share information and collaborate on software. CDC use of GitHub does not imply an endorsement of any one particular service, product, or enterprise. \ No newline at end of file From c01923aaf84ce714f22c0e5800bebb7ee9ddb2a2 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Wed, 9 Oct 2024 11:52:19 -0600 Subject: [PATCH 14/19] Trying to split the default message in multiple lines --- post-artifact/action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index bc601d0..2fff21f 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -17,7 +17,10 @@ inputs: or as GFM formatted link. Use the `{ artifact-name }` placeholder to include the artifact name in the message. required: false - default: 'Thank you for your contribution @${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!' + default: | + Thank you for your contribution @${{ github.actor }} :rocket:!\Your { \ + artifact-name } is ready for download :point_right: [here]({ \ + artifact-url }) :point_left:! python: description: | The path to the Python executable. This input is optional and From d701180a441b4c6d697d9f563a8a1a4948aaad44 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Wed, 9 Oct 2024 11:53:41 -0600 Subject: [PATCH 15/19] Trying to split the default message in multiple lines v2 --- post-artifact/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index 2fff21f..2ef217e 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -18,9 +18,9 @@ inputs: placeholder to include the artifact name in the message. required: false default: | - Thank you for your contribution @${{ github.actor }} :rocket:!\Your { \ - artifact-name } is ready for download :point_right: [here]({ \ - artifact-url }) :point_left:! + Thank you for your contribution @${{ github.actor }} :rocket:! Your \ + { artifact-name } is ready for download :point_right: \ + [here]({ artifact-url }) :point_left:! python: description: | The path to the Python executable. This input is optional and From 0c48196cd443897aa29f5500661654a951a7ebe7 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Wed, 9 Oct 2024 11:55:27 -0600 Subject: [PATCH 16/19] Reverting change on default value of message (can't get it right) --- post-artifact/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index 2ef217e..bc601d0 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -17,10 +17,7 @@ inputs: or as GFM formatted link. Use the `{ artifact-name }` placeholder to include the artifact name in the message. required: false - default: | - Thank you for your contribution @${{ github.actor }} :rocket:! Your \ - { artifact-name } is ready for download :point_right: \ - [here]({ artifact-url }) :point_left:! + default: 'Thank you for your contribution @${{ github.actor }} :rocket:! Your { artifact-name } is ready for download :point_right: [here]({ artifact-url }) :point_left:!' python: description: | The path to the Python executable. This input is optional and From 01e2b0cefa1ce6cc0b8a6f3ae42091fe683b90af Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 15 Oct 2024 18:02:11 -0600 Subject: [PATCH 17/19] Moving the if statement outside of the action (user-aware) --- .github/workflows/test-post-artifact.yml | 2 ++ post-artifact/README.md | 2 ++ post-artifact/action.yml | 11 ++--------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-post-artifact.yml b/.github/workflows/test-post-artifact.yml index c586ff6..bf9b081 100644 --- a/.github/workflows/test-post-artifact.yml +++ b/.github/workflows/test-post-artifact.yml @@ -38,6 +38,7 @@ jobs: apt install -y --no-install-recommends gh - name: Post the artifact + if: ${{ github.event_name == 'pull_request' }} uses: ./post-artifact with: artifact-name: 'readme-rocker' @@ -68,6 +69,7 @@ jobs: name: ${{ format('readme-{0}', matrix.os) }} - name: Post the artifact + if: ${{ github.event_name == 'pull_request' }} uses: ./post-artifact with: artifact-name: ${{ format('readme-{0}', matrix.os) }} diff --git a/post-artifact/README.md b/post-artifact/README.md index c7a0ac5..02f3ff2 100644 --- a/post-artifact/README.md +++ b/post-artifact/README.md @@ -36,6 +36,7 @@ Here are the contents of a job that (i) uploads an artifact using `actions/uploa # Post the artifact pulling the id from the `readme` step. - name: Post the artifact uses: CDCgov/cfa-actions/post-artifact@main + if: ${{ github.event_name == 'pull_request' }} with: artifact-name: readme gh-token: ${{ secrets.GITHUB_TOKEN }} @@ -85,6 +86,7 @@ jobs: # Post the artifact pulling the id from the `readme` step. # The msg will refer to the arfitact as 'README file'. - name: Post the artifact + if: ${{ github.event_name == 'pull_request' }} uses: CDCgov/cfa-actions/post-artifact@main with: artifact-name: readme diff --git a/post-artifact/action.yml b/post-artifact/action.yml index bc601d0..33a8d71 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -35,7 +35,6 @@ runs: # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts - name: "Get list of available artifacts and store as .json" - if: ${{ github.event_name == 'pull_request' }} run: | gh api \ -H "Accept: application/vnd.github+json" \ @@ -46,7 +45,6 @@ runs: GH_TOKEN: ${{ inputs.gh-token }} - name: Fetch metadata for the target artifact - if: ${{ github.event_name == 'pull_request' }} run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/fetch-artifact-meta.py shell: bash env: @@ -54,7 +52,6 @@ runs: SHA: ${{ github.sha }} - name: Get artifact id - if: ${{ github.event_name == 'pull_request' }} id: artifact-meta run: | echo "id=$(cat '${{ github.sha }}_artifact_id')" >> $GITHUB_OUTPUT @@ -62,7 +59,6 @@ runs: shell: bash - name: Compose message - if: ${{ github.event_name == 'pull_request' }} run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/compose-msg.py shell: bash env: @@ -76,7 +72,6 @@ runs: EXP_DATE: ${{ steps.artifact-meta.outputs.expires_at }} - name: Get the event - if: ${{ github.event_name == 'pull_request' }} run: | gh api \ -H "Accept: application/vnd.github+json" \ @@ -87,7 +82,6 @@ runs: GH_TOKEN: ${{ inputs.gh-token }} - name: Find the comment - if: ${{ github.event_name == 'pull_request' }} run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/find-comment.py shell: bash env: @@ -95,7 +89,6 @@ runs: ARTIFACT_NAME: ${{ inputs.artifact-name }} - name: Putting the contents of _msg.txt into an environment var - if: ${{ github.event_name == 'pull_request' }} id: set-env run: | echo "ID=$(cat _ID-${{ github.sha }})" >> $GITHUB_OUTPUT @@ -105,7 +98,7 @@ runs: # See: # https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#update-an-issue-comment - name: Add comment - if: ${{ github.event_name == 'pull_request' && steps.set-env.outputs.FOUND == 'false' }} + if: ${{ steps.set-env.outputs.FOUND == 'false' }} run: | echo "No comment from github-bot found, adding a new one." gh pr comment -R ${{ github.repository }} \ @@ -115,7 +108,7 @@ runs: GH_TOKEN: ${{ inputs.gh-token }} - name: Update comment - if: ${{ github.event_name == 'pull_request' && steps.set-env.outputs.FOUND == 'true' }} + if: ${{ steps.set-env.outputs.FOUND == 'true' }} run: | echo "Editing original comment id: ${{ steps.set-env.outputs.ID }}." gh api \ From 1ece256ad7e867ba8c67745397d534bf8b2d9ff8 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 22 Oct 2024 17:16:56 -0600 Subject: [PATCH 18/19] Adding an error message if the user is not running under a PR --- post-artifact/action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index 33a8d71..ec0a133 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -33,6 +33,13 @@ runs: steps: + - name: Check this is a PR + if: ${{ github.event_name != 'pull_request' }} + run: + echo "This action must only run in pull requests." + echo "See https://github.com/CDCgov/cfa-actions for more information." + exit 1 + # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts - name: "Get list of available artifacts and store as .json" run: | From d8dd23bb226eefce64bf9055280e8c3a5b85fe4d Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 22 Oct 2024 17:17:50 -0600 Subject: [PATCH 19/19] Adding the shell to the first step --- post-artifact/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/post-artifact/action.yml b/post-artifact/action.yml index ec0a133..d5d3499 100644 --- a/post-artifact/action.yml +++ b/post-artifact/action.yml @@ -39,6 +39,7 @@ runs: echo "This action must only run in pull requests." echo "See https://github.com/CDCgov/cfa-actions for more information." exit 1 + shell: bash # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts - name: "Get list of available artifacts and store as .json"