-
Notifications
You must be signed in to change notification settings - Fork 8
/
action.yml
183 lines (166 loc) · 7.04 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: 'gitStream repo agent'
description: 'Public GitHub action for gitStream Continuous Merge'
inputs:
full_repository:
description: 'Path of full Repository'
required: true
head_ref:
description: 'Head Branch Ref to checkout to'
required: true
base_ref:
description: 'Base Branch Ref to checkout to'
required: true
client_payload:
description: 'The client payload'
required: true
installation_id:
description: 'The github app installation id'
required: false
resolver_url:
description: 'Resolver url to send results to'
required: true
resolver_token:
description: 'Optional token for resolver'
required: false
debug_mode:
description: 'Run parser in debug mode'
required: false
default: 'false'
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: 20.12.2
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Create GitStream folder
shell: bash
run: |
rm -rf gitstream && rm -rf code && mkdir gitstream
cd gitstream && mkdir repo
- name: Checkout base branch
uses: actions/checkout@v4
with:
repository: ${{ inputs.full_repository }}
ref: ${{ inputs.base_ref }}
path: gitstream/repo/
token: ${{ fromJSON(fromJSON(inputs.client_payload)).githubToken || github.token }}
- name: Escape single quotes
id: safe-strings
uses: actions/github-script@v7
env:
BASE_REF_ARG: ${{ inputs.base_ref }}
HEAD_REF_ARG: ${{ inputs.head_ref }}
PAYLOAD_ARG: ${{ inputs.client_payload }}
URL_ARG: ${{ fromJSON(fromJSON(inputs.client_payload)).headHttpUrl || fromJSON(fromJSON(inputs.client_payload)).repoUrl }}
with:
script: |
try {
function convertToSafeString(input) {
return (input || '').replace(/['`]/g, "\\$&");
};
function escapeApostrophe(input) {
return (input || '').replace(/'/g, "\\'");
};
const base_ref = escapeApostrophe(process.env.BASE_REF_ARG);
const head_ref = escapeApostrophe(process.env.HEAD_REF_ARG);
const url = convertToSafeString(process.env.URL_ARG);
const client_payload = convertToSafeString(process.env.PAYLOAD_ARG);
core.setOutput('base_ref', base_ref);
core.setOutput('head_ref', head_ref);
core.setOutput('url', url);
core.setOutput('client_payload', client_payload);
} catch (err) {
core.error(`Failed producing safe string: ${err}`);
process.exit(1);
}
- name: Get condition variables
uses: actions/github-script@v7
env:
IS_NON_COMMIT_ARG: ${{ fromJSON(fromJSON(inputs.client_payload)).isNonCommitEvent }}
ENABLE_CACHE_ARG: ${{ env.ENABLE_CACHE }}
RUN_ID_ARG: ${{ fromJSON(fromJSON(inputs.client_payload)).artifactRunId }}
with:
script: |
require('${{ github.action_path }}/scripts/get-condition-vars.js')(core);
- name: Download cache artifact for cm repo
id: download-cache-for-cm-repo
uses: actions/download-artifact@v4
if: ${{ env.SKIP_GIT_CLONE == 'true' && fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true }}
continue-on-error: true
with:
github-token: ${{ fromJSON(fromJSON(inputs.client_payload)).githubToken || github.token }}
repository: '${{ fromJSON(fromJSON(inputs.client_payload)).owner }}/${{ fromJSON(fromJSON(inputs.client_payload)).cmRepo }}'
run-id: ${{ fromJSON(fromJSON(inputs.client_payload)).artifactRunId }}
name: output
path: code/output
- name: Download cache artifact when cmRepo is false
id: download-cache
uses: actions/download-artifact@v4
if: ${{ env.SKIP_GIT_CLONE == 'true' && fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == false}}
continue-on-error: true
with:
github-token: ${{ fromJSON(fromJSON(inputs.client_payload)).githubToken || github.token }}
repository: ${{ inputs.full_repository }}
run-id: ${{ fromJSON(fromJSON(inputs.client_payload)).artifactRunId }}
name: output
path: code/output
- name: Check if download cache artifact failed
uses: actions/github-script@v7
env:
ARTIFACT_OUTCOME_ARG: ${{ steps.download-cache.outcome }}
ARTIFACT_OUTCOME_CM_REPO_ARG: ${{ steps.download-cache-for-cm-repo.outcome }}
with:
script: require('${{ github.action_path }}/scripts/check-cache-download-status')(core);
- name: Checkout Pull Request branches history
if: ${{ env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true' }}
shell: bash
run: |
ALL=2147483647
cd gitstream && cd repo
git fetch --deepen=$ALL origin $'${{ steps.safe-strings.outputs.base_ref }}'
git remote add upstream $'${{ steps.safe-strings.outputs.url }}'
git fetch --deepen=$ALL upstream $'${{ steps.safe-strings.outputs.head_ref }}'
git checkout -b $'upstream/${{ steps.safe-strings.outputs.head_ref}}' $'upstream/${{ steps.safe-strings.outputs.head_ref}}'
git checkout $'${{ steps.safe-strings.outputs.base_ref }}'
git checkout $'${{ steps.safe-strings.outputs.head_ref }}'
- name: Create cm folder
if: ${{ env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true' }}
shell: bash
run: cd gitstream && mkdir cm
- name: Checkout cm repo
uses: actions/checkout@v4
if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true && (env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true')}}
with:
repository: '${{ fromJSON(fromJSON(inputs.client_payload)).owner }}/${{ fromJSON(fromJSON(inputs.client_payload)).cmRepo }}'
ref: ${{ fromJSON(fromJSON(inputs.client_payload)).cmRepoRef }}
path: gitstream/cm/
- name: Volume folder
shell: bash
run: mv gitstream code
- name: Install Dependencies for plugins
shell: bash
run: npm i --silent moment lodash axios @octokit/rest@20.1.1
- name: Run RulesEngine
shell: bash
run: node ${{ github.action_path }}/dist/index.js
env:
HEAD_REF: ${{ steps.safe-strings.outputs.head_ref }}
BASE_REF: ${{ steps.safe-strings.outputs.base_ref }}
CLIENT_PAYLOAD: ${{ steps.safe-strings.outputs.client_payload }}
RULES_RESOLVER_URL: ${{ inputs.resolver_url }}
RULES_RESOLVER_TOKEN: ${{ inputs.resolver_token }}
DEBUG_MODE: ${{ inputs.debug_mode }}
SHOULD_SKIP_CLONE: ${{ env.SKIP_GIT_CLONE == 'true' && env.CACHE_DOWNLOAD_FAILED == 'false'}}
ENABLE_CACHE: ${{ env.ENABLE_CACHE }}
ENABLE_DEBUG_ARTIFACTS: ${{ env.ENABLE_DEBUG_ARTIFACTS }}
RUN_ID: ${{ github.run_id }}
- name: Upload artifacts
if: ${{ env.ENABLE_DEBUG_ARTIFACTS == 'true' || env.ENABLE_CACHE == 'true' }}
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: output
path: code/output