-
Notifications
You must be signed in to change notification settings - Fork 125
98 lines (82 loc) · 3.87 KB
/
pr.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
name: Open API PR check
on:
pull_request:
paths:
- '**'
jobs:
pr-health-check:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install yaml lint
run: pip install yamllint
# - name: Run yamllint
# run: |
# git fetch > /dev/null 2>&1
# git checkout ${{github.head_ref}}
# find . -type f \( -name "*.yaml" \) > yaml_files.txt
# if [ -s yaml_files.txt ]; then
# echo "linting the following yaml files:"
# cat yaml_files.txt
# xargs yamllint < yaml_files.txt
# fi
- name: Install octokit dependencies
run: npm i
working-directory: ${{ github.workspace }}/.github/octokit
- name: Get github app access token
id: get_access_token
env:
GITHUB_APP_ID: ${{ secrets.XERO_GITHUB_APP_ID }}
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_GITHUB_APPLICATION_KEY }}
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js')
const token = await getAccessToken()
return token
- name: Calling All SDK workflows
run: |
dispatchId=$((10000 + RANDOM % 90000))
echo "dispatchId: $dispatchId"
curl -X POST \
-H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/dispatches \
-d '{"ref":"PETOSS-536-enabling-workflow-dispatch","inputs":{"branch_name": "${{github.head_ref}}", "dispatch_id": $dispatchId}}'
# - name: Get workflow run ID
# id: get-run-id
# run: |
# run_id=$(curl -s \
# -H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
# -H "Accept: application/vnd.github.everest-preview+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/runs \
# | jq -r '.workflow_runs[0] | select(.head_branch=="PETOSS-536-enabling-workflow-dispatch") | .id' | head -n 1)
# if [ -z "$run_id"]; then
# echo "Failed to retrieve workflow run id"
# exit 1
# else
# echo "workflow run ID: $run_id"
# fi
- name: Get workflow run ID
id: get-run-id
run: |
workflow_run=$(curl -s \
-H 'Authorization: Bearer ${{ steps.get_access_token.outputs.result }}' \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/pr.yml/runs \
| jq -r '.workflow_runs[0]')
echo "workflow run: $workflow_run"
run_id=(echo $workflow_run | jq -r '.id')
echo "workflow run ID: $run_id"