-
Notifications
You must be signed in to change notification settings - Fork 61
106 lines (97 loc) · 3.42 KB
/
unicorns.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
name: Unicorn CI/CD pipeline
on:
workflow_dispatch:
create:
pull_request:
types:
- opened
- synchronize
- labeled
- closed
pull_request_review:
types: [submitted]
concurrency:
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
group: push-unicorn${{ github.head_ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
printJob:
name: Print event
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
check-approved:
name: Is PR approved
runs-on: ubuntu-latest
outputs:
IS_APPROVED: ${{ steps.check-approved.outputs.result }}
steps:
- name: Check if PR is approved
id: check-approved
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (!context || !context.payload || !context.payload.pull_request) {
return false;
}
var reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
if(!reviews || !reviews.data == null) {
return false;
}
var declined = reviews.data.filter(review => review.state != 'APPROVED').length > 0;
var pending = context.payload.pull_request.requested_teams.length > 0
console.log(!(declined && pending) ? 'Pr is approved' : 'Pr is not approved');
return !(declined && pending);
- name: output
run: echo "IS_APPROVED=${{ steps.check-approved.outputs.result }}" >> $GITHUB_OUTPUT
check-unicorn:
name: Is this a unicorn PR
needs: check-approved
if: ${{ needs.check-approved.outputs.IS_APPROVED }}"
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 10
steps:
- run: echo "selected runner = ${{ runner.name }}"
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Setup yarn
run: corepack enable
- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-cache: 'node_modules,generated-files'
- name: Check unicorn affected
id: unicorn-affected
env:
BaseRef: ${{ github.base_ref }} #The target branch e.g. main (feature/unicorn-app)
HeadRef: ${{ github.head_ref }} #The branch being merged e.g. (unicorn-pipe-rel3)
run: |
echo "Comparing nx affected for $HeadRef using origin/$BaseRef as base branch"
echo IS_UNICORN=$(node scripts/ci/unicorn-utils.mjs "{\"baseBranch\": \"origin/$BaseRef\", \"mergeBranch\": \"$HeadRef\" }") >> "$GITHUB_OUTPUT"
- name: Results
run: |
echo "Unicorn = ${{ steps.unicorn-affected.outputs.IS_UNICORN }}"
- name: Find Latest Release Branch
run: |
node scripts/ci/get-last-release.mjs $(git branch -r)
- run: "echo 'latest release: ${{ steps.get_latest_release.outputs.data }}'"