generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
130 lines (119 loc) · 4.74 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: post-artifact
description: |
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 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, 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:
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:
- 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
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"
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: Fetch metadata for the target artifact
run: ${{ inputs.python }} ${GITHUB_ACTION_PATH}/scripts/fetch-artifact-meta.py
shell: bash
env:
ARTIFACT_NAME: ${{ inputs.artifact-name }}
SHA: ${{ github.sha }}
- name: Get artifact id
id: artifact-meta
run: |
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
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-meta.outputs.id }}
SHA: ${{ github.sha }}
EXP_DATE: ${{ steps.artifact-meta.outputs.expires_at }}
- name: Get the event
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
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
id: set-env
run: |
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: ${{ 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 }} -F msg-${{ github.sha }}.txt
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}
- name: Update comment
if: ${{ 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=@msg-${{ github.sha }}.txt'
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}