Repository navigation
83 lines (77 loc) · 3.3 KB
/
Copy pathdiff-dep.yml
File metadata and controls
83 lines (77 loc) · 3.3 KB
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
name: Post dependency compare link
on:
workflow_call:
inputs:
dep:
type: string
required: true
reqs_file:
type: string
default: 'requirements.in'
jobs:
post-comment:
name: Post comment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
# Generate a GitHub link to a page that displays all commits/changes between
# the old dependency version and the new one, or an empty string if the dependency
# wasn't changed.
- name: Get compare URL
id: get-compare-url
run: |
compare_url=$(git diff -r HEAD^ ${{ inputs.reqs_file }} \
| grep ${{ inputs.dep }}\/archive \
| cut -d '/' -f 7 \
| cut -d '.' -f 1 \
| awk 'NR%2{printf "https://github.com/codecov/${{ inputs.dep }}/compare/%s...",$0;next;}1')
echo "Compare URL: $compare_url"
echo "COMPARE_URL=$compare_url" >> $GITHUB_OUTPUT
# If our dep was changed, check if we've already made a comment and cached its ID
- name: Cache check
id: cache-check
if: steps.get-compare-url.outputs.COMPARE_URL != ''
uses: actions/cache@v4
with:
path: comment-id.txt
key: comment-id-pr-${{ github.event.pull_request.number }}
# If our dep was changed and there is no comment ID in the cache, create a new comment
- name: Create comment
id: create-comment
if: ${{ steps.get-compare-url.outputs.COMPARE_URL != '' && steps.cache-check.outputs.cache-hit != 'true' }}
uses: actions/github-script@v7
with:
script: |
return github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'This PR includes changes to `${{ inputs.dep }}`. Please review them here: ${{ steps.get-compare-url.outputs.COMPARE_URL }}'
})
# Whether we got it from cache or the comment created above, put the comment ID in
# the cached output file + set it as the output of this step
- name: Get comment ID
id: get-comment-id
if: steps.get-compare-url.outputs.COMPARE_URL != ''
run: |
if [ ! -f comment-id.txt ]; then
echo "Comment was newly created; getting ID out of response"
echo '${{ steps.create-comment.outputs.result }}' | jq '.data.id' > comment-id.txt
fi
echo "Comment ID is $(cat comment-id.txt)"
echo "COMMENT_ID=$(cat comment-id.txt)" >> $GITHUB_OUTPUT
# If we have changes to our dep, and we got a comment ID from the cache, update the comment.
- name: Update comment
id: update-comment
if: ${{ steps.get-compare-url.outputs.COMPARE_URL != '' && steps.cache-check.outputs.cache-hit == 'true' }}
uses: actions/github-script@v7
with:
script: |
return github.rest.issues.updateComment({
comment_id: ${{ steps.get-comment-id.outputs.COMMENT_ID }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'This PR includes changes to `${{ inputs.dep }}`. Please review them here: ${{ steps.get-compare-url.outputs.COMPARE_URL }}'
})