forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (87 loc) · 3.67 KB
/
reusable_export_pr_details.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
name: Export previously recorded PR
on:
workflow_call:
inputs:
record_pr_workflow_id:
description: "Record PR workflow execution ID to download PR details"
required: true
type: number
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
description: "Repository full name for runner integrity"
required: true
type: string
secrets:
token:
description: "GitHub Actions temporary and scoped token"
required: true
# Map the workflow outputs to job outputs
outputs:
prNumber:
description: "PR Number"
value: ${{ jobs.export_pr_details.outputs.prNumber }}
prTitle:
description: "PR Title"
value: ${{ jobs.export_pr_details.outputs.prTitle }}
prBody:
description: "PR Body as string"
value: ${{ jobs.export_pr_details.outputs.prBody }}
prAuthor:
description: "PR author username"
value: ${{ jobs.export_pr_details.outputs.prAuthor }}
prAction:
description: "PR event action"
value: ${{ jobs.export_pr_details.outputs.prAction }}
prIsMerged:
description: "Whether PR is merged"
value: ${{ jobs.export_pr_details.outputs.prIsMerged }}
jobs:
export_pr_details:
# see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
if: inputs.workflow_origin == 'awslabs/aws-lambda-powertools-python'
runs-on: ubuntu-latest
env:
FILENAME: pr.txt
# Map the job outputs to step outputs
outputs:
prNumber: ${{ steps.prNumber.outputs.prNumber }}
prTitle: ${{ steps.prTitle.outputs.prTitle }}
prBody: ${{ steps.prBody.outputs.prBody }}
prAuthor: ${{ steps.prAuthor.outputs.prAuthor }}
prAction: ${{ steps.prAction.outputs.prAction }}
prIsMerged: ${{ steps.prIsMerged.outputs.prIsMerged }}
steps:
- name: Checkout repository # in case caller workflow doesn't checkout thus failing with file not found
uses: actions/checkout@v3
- name: "Download previously saved PR"
uses: actions/github-script@v6
env:
WORKFLOW_ID: ${{ inputs.record_pr_workflow_id }}
# For security, we only download artifacts tied to the successful PR recording workflow
with:
github-token: ${{ secrets.token }}
script: |
const script = require('.github/scripts/download_pr_artifact.js')
await script({github, context, core})
# NodeJS standard library doesn't provide ZIP capabilities; use system `unzip` command instead
- name: "Unzip PR artifact"
run: unzip pr.zip
# NOTE: We need separate steps for each mapped output and respective IDs
# otherwise the parent caller won't see them regardless on how outputs are set.
- name: "Export Pull Request Number"
id: prNumber
run: echo ::set-output name=prNumber::$(jq -c '.number' ${FILENAME})
- name: "Export Pull Request Title"
id: prTitle
run: echo ::set-output name=prTitle::$(jq -c '.pull_request.title' ${FILENAME})
- name: "Export Pull Request Body"
id: prBody
run: echo ::set-output name=prBody::$(jq -c '.pull_request.body' ${FILENAME})
- name: "Export Pull Request Author"
id: prAuthor
run: echo ::set-output name=prAuthor::$(jq -c '.pull_request.user.login' ${FILENAME})
- name: "Export Pull Request Action"
id: prAction
run: echo ::set-output name=prAction::$(jq -c '.action' ${FILENAME})
- name: "Export Pull Request Merged status"
id: prIsMerged
run: echo ::set-output name=prIsMerged::$(jq -c '.pull_request.merged' ${FILENAME})