-
Notifications
You must be signed in to change notification settings - Fork 77
140 lines (124 loc) · 5.94 KB
/
publishVersionCheckResults.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
name: Publish Version Check Results
on:
workflow_call:
inputs:
botGithubId:
description: The id of the bot's github account that adds the information comment
type: string
required: true
secrets:
githubBotPAT:
description: The personal access token (with scope 'public_repo') of the bot to push a required change to a PR branch in a fork.
required: true
permissions: {} # all none
env:
COMMENT_FIRST_LINE: 'This pull request changes some projects for the first time in this development cycle'
jobs:
versions-check-result:
name: Publish Version Check Results
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
steps:
- name: Search version increment git patch
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: search-patch
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
run_id: context.payload.workflow_run.id,
...context.repo
})
let artifact = allArtifacts.data.artifacts.find(artifact => artifact.name == 'versions-git-patch')
return artifact?.id
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
if: steps.search-patch.outputs.result
with:
ref: '${{ github.event.workflow_run.head_sha }}'
persist-credentials: false #Opt out from persisting the default Github-token authentication in order to enable use of the bot's PAT when pushing below
- name: Download version increment git patch
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: fetch-patch
if: steps.search-patch.outputs.result
with:
script: |
let download = await github.rest.actions.downloadArtifact({
artifact_id: ${{ steps.search-patch.outputs.result }},
archive_format: 'zip',
...context.repo
})
let fs = require('fs')
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/patch.zip`, Buffer.from(download.data))
await exec.exec('unzip', ['patch.zip'])
let pr_number = Number(fs.readFileSync('github_pull_request_number.txt'))
core.setOutput('pull_request_number', pr_number)
await io.rmRF('patch.zip')
await io.rmRF('github_pull_request_number.txt')
- name: Apply and push version increment
id: git-commit
if: steps.search-patch.outputs.result
env:
REPOSITORY_NAME: ${{ github.event.workflow_run.head_repository.full_name }}
BRANCH_NAME: ${{ github.event.workflow_run.head_branch }}
BOT_PA_TOKEN: ${{ secrets.githubBotPAT }}
run: |
set -x
# Set initial placeholder name/mail and read it from the patch later
git config --global user.email 'foo@bar'
git config --global user.name 'Foo Bar'
git am version_increments.patch
# Read the author's name+mail from the just applied patch and recommit it with both set as committer
botMail=$(git log -1 --pretty=format:'%ae')
botName=$(git log -1 --pretty=format:'%an')
git config --global user.email "${botMail}"
git config --global user.name "${botName}"
git commit --amend --no-edit
fileList=$(git diff-tree --no-commit-id --name-only HEAD -r)
echo "file-list<<EOF" >> $GITHUB_OUTPUT
echo "$fileList" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
git push \
"https://oauth2:${BOT_PA_TOKEN}@github.com/${REPOSITORY_NAME}.git" \
"HEAD:refs/heads/${BRANCH_NAME}"
- name: Find existing information comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
id: search-comment
if: steps.fetch-patch.outputs.pull_request_number
with:
body-regex: '^${{ env.COMMENT_FIRST_LINE }}'
issue-number: ${{ steps.fetch-patch.outputs.pull_request_number }}
comment-author: ${{ inputs.botGithubId }}
direction: last
- name: Add or update information comment
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: always()
env:
FILELIST: ${{ steps.git-commit.outputs.file-list }}
with:
github-token: ${{ secrets.githubBotPAT }}
script: |
const fs = require('fs')
const fileList = process.env.FILELIST
if (fileList) { // if list is empty, no versions were changed
const commentBody = `
${{ env.COMMENT_FIRST_LINE }}.
Therefore the following files need a version increment:
\`\`\`
${fileList}
\`\`\`
An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the _git patch_.
<details>
<summary>Git patch</summary>
\`\`\`
${ fs.readFileSync( process.env.GITHUB_WORKSPACE + '/version_increments.patch', {encoding: 'utf8'}).trim() }
\`\`\`
</details>
Further information are available in [Common Build Issues - Missing version increments](https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/wiki/Common-Build-Issues#missing-version-increments).
`.trim()
const prNumber = '${{ steps.fetch-patch.outputs.pull_request_number }}'
const existingCommentId = '${{ steps.search-comment.outputs.comment-id }}'
if (existingCommentId) {
github.rest.issues.updateComment({...context.repo, comment_id: existingCommentId, body: commentBody })
} else {
github.rest.issues.createComment({...context.repo, issue_number: prNumber, body: commentBody })
}
}