-
Notifications
You must be signed in to change notification settings - Fork 23
273 lines (251 loc) · 9.11 KB
/
issue_ops.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: actions-importer-issue-ops
on:
issue_comment:
types: [created]
permissions:
contents: read
issues: write
defaults:
run:
shell: bash
env:
GITHUB_INSTANCE_URL: ${{ secrets.GH_INSTANCE_URL || 'https://github.com' }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
JENKINS_INSTANCE_URL: ${{ secrets.JENKINS_INSTANCE_URL }}
JENKINS_USERNAME: ${{ secrets.jenkins_username }}
JENKINS_ACCESS_TOKEN: ${{ secrets.jenkins_access_token }}
JENKINSFILE_ACCESS_TOKEN: ${{ secrets.jenkinsfile_access_token }}
AZURE_DEVOPS_ACCESS_TOKEN: ${{ secrets.azure_devops_access_token }}
TRAVIS_CI_ACCESS_TOKEN: ${{ secrets.travis_ci_access_token }}
TRAVIS_CI_SOURCE_GITHUB_ACCESS_TOKEN: ${{ secrets.travis_ci_source_github_access_token }}
GITLAB_ACCESS_TOKEN: ${{ secrets.gitlab_access_token }}
GITLAB_INSTANCE_URL: ${{ secrets.gitlab_instance_url || 'https://gitlab.com' }}
CIRCLE_CI_ACCESS_TOKEN: ${{ secrets.circle_ci_access_token }}
CIRCLE_CI_SOURCE_GITHUB_ACCESS_TOKEN: ${{ secrets.circle_ci_source_github_access_token }}
BAMBOO_ACCESS_TOKEN: ${{ secrets.bamboo_access_token }}
BAMBOO_INSTANCE_URL: ${{ secrets.bamboo_instance_url }}
BITBUCKET_ACCESS_TOKEN: ${{ secrets.bitbucket_access_token }}
jobs:
execute-actions-importer:
runs-on: ubuntu-latest
outputs:
command: ${{ steps.prepare.outputs.command }}
log-filename: ${{ steps.logs.outputs.filename }}
steps:
- name: Install GitHub Actions Importer
run: |
gh actions-importer version || gh extension install github/gh-actions-importer
gh actions-importer update
env:
GH_TOKEN: ${{ github.token }}
- uses: actions/github-script@v7
if: always()
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['actions-importer-running']
})
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
# ImageOs must be configured to match the OS of the runner when using self-hosted runners.
# env:
# ImageOS: ubuntu22
- name: Install Dependencies
run: bundle install
env:
BUNDLE_WITHOUT: development
- name: Prepare arguments
id: prepare
env:
ISSUE_BODY: ${{ github.event.issue.body }}
COMMENT_BODY: ${{ github.event.comment.body }}
LABELS: ${{ toJSON(github.event.issue.labels.*.name) }}
run: |
./bin/parse_issue "$ISSUE_BODY" "$COMMENT_BODY" "$LABELS"
- name: Validate arguments
run: |
if [ -z "${{ steps.prepare.outputs.provider }}" ]; then
echo "Unable to determine provider"
exit 1
elif [ -z "${{ steps.prepare.outputs.command }}" ]; then
echo "Unable to determine command"
exit 1
fi
- name: execute actions-importer
run: |
gh actions-importer ${{ steps.prepare.outputs.command }} ${{ steps.prepare.outputs.provider }} \
${{ steps.prepare.outputs.args }} \
--output-dir output
- uses: actions/upload-artifact@v4
if: always()
with:
path: output/
name: output
- if: always()
id: logs
run: |
path=$(ls output/log/*.log | head -1)
filename=$(basename "$path")
echo "LOG_FILE_PATH=$path" >> $GITHUB_ENV
echo "filename=$filename" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
if: always()
with:
path: ${{ env.LOG_FILE_PATH }}
name: logs
audit:
runs-on: ubuntu-latest
if: needs.execute-actions-importer.outputs.command == 'audit'
needs: execute-actions-importer
steps:
- uses: actions/download-artifact@v4
if: always()
with:
name: output
- uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const summaryText = fs.readFileSync("./audit_summary.md", "utf8")
const MAX_LENGTH = 64000
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`
const body = `Audit successfully completed :rocket:
Download full results [here](${artifactUrl})
<details>
<summary>Audit summary :point_down:</summary>
\`\`\`
${summaryText.substring(0, Math.min(summaryText.length, MAX_LENGTH))}
\`\`\`
</details>
`
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
dry-run:
runs-on: ubuntu-latest
if: needs.execute-actions-importer.outputs.command == 'dry-run'
needs: execute-actions-importer
steps:
- uses: actions/download-artifact@v4
if: always()
with:
name: output
- uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const directory = "${{ github.workspace }}/"
const globber = await glob.create(`${directory}**/*.yml`)
const MAX_LENGTH = 64000
let currentLength = 0
const workflows = []
for await (const file of globber.globGenerator()) {
const content = fs.readFileSync(file, 'utf8')
const data = [
"<details>",
` <summary>${file.substring(directory.length)}</summary>`,
"",
"```yaml",
content,
"```",
"</details>",
""
]
for (const element of data) {
currentLength += element.length;
}
if (currentLength > MAX_LENGTH){
break
}
workflows.push(...data)
}
const body = `Dry run was successful :boom:
Transformed workflows:
${workflows.join("\n")}
`
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
migrate:
runs-on: ubuntu-latest
if: needs.execute-actions-importer.outputs.command == 'migrate'
needs: execute-actions-importer
steps:
- uses: actions/download-artifact@v4
if: always()
with:
name: logs
- id: pull-request-url
run: |
pullRequest=$(grep "${{ env.pullRequestPattern }}" ${{ needs.execute-actions-importer.outputs.log-filename }} | sed -rn "s/^.*${{ env.pullRequestPattern }}'(.+)'.*$/\1/p")
echo $pullRequest
echo "output=$pullRequest" >> $GITHUB_OUTPUT
env:
pullRequestPattern: "Pull request: "
- uses: actions/github-script@v7
env:
PULL_REQUEST_URL: "${{ steps.pull-request-url.outputs.output }}"
with:
script: |
const body = `Migration was successful :sparkles:
Continue to the [pull request](${process.env.PULL_REQUEST_URL}) to complete the migration.
`
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
} catch(e) {
console.log(e)
}
cleanup:
runs-on: ubuntu-latest
needs: [execute-actions-importer, audit, migrate, dry-run]
if: always()
steps:
- uses: actions/download-artifact@v4
if: always() && needs.execute-actions-importer.result == 'failure'
with:
name: logs
- uses: actions/github-script@v7
if: always() && needs.execute-actions-importer.result == 'failure'
with:
script: |
const fs = require('fs')
const MAX_LENGTH = 64000
const logData = fs.readFileSync("${{ needs.execute-actions-importer.outputs.log-filename }}", "utf8")
const body = `Something went wrong. Please check the logs for more information.
<details>
<summary>Logs :point_down:</summary>
\`\`\`
${logData.substring(0, Math.min(logData.length, MAX_LENGTH))}
\`\`\`
</details>
`
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
- uses: actions/github-script@v7
if: always()
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'actions-importer-running'
});