-
Notifications
You must be signed in to change notification settings - Fork 12
219 lines (183 loc) · 8.44 KB
/
release-phase-1-internal.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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
---
name: Release – Phase 1 (Internal)
on:
workflow_call:
inputs:
major:
required: true
type: string
minor:
required: true
type: string
patch:
required: true
type: string
permissions: {}
jobs:
release:
name: Release ${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}
runs-on: ubuntu-latest
env:
version: ${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}
permissions:
pull-requests: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Validate major
shell: pwsh
run: "[int]::Parse(${{ inputs.major }})"
- name: Validate minor
shell: pwsh
run: "[int]::Parse(${{ inputs.minor }})"
- name: Validate patch
shell: pwsh
run: "[int]::Parse(${{ inputs.patch }})"
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# Fine-grained Personal Access Token (PAT) with the following permissions for microsoft/PR-Metrics:
# - Read access to Metadata
# - Read and Write access to Actions, Code (aka Contents), and Workflows
token: ${{ secrets.RELEASE_PHASE_1_CHECKOUT }}
- name: Version Number – README.md
shell: pwsh
run: |-
$FilePath = 'README.md'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace 'PR-Metrics@v\d+\.\d+\.\d+', 'PR-Metrics@v${{ env.version }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – package.json
shell: pwsh
run: |-
$FilePath = 'package.json'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace '"version": "\d+\.\d+\.\d+"', '"version": "${{ env.version }}"'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – vss-extension.json
shell: pwsh
run: |-
$FilePath = 'src/vss-extension.json'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace '"version": "\d+\.\d+\.\d+"', '"version": "${{ env.version }}"'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – release-trigger.txt
shell: pwsh
run: Set-Content -Path '.github/workflows/support/release-trigger.txt' -Value ${{ env.version }}
- name: Version Number – task.json
shell: pwsh
run: |-
$FilePath = 'src/task/task.json'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace 'PR Metrics v\d+\.\d+\.\d+', 'PR Metrics v${{ env.version }}'
$FileContents = $FileContents -replace '"Major": \d+', '"Major": ${{ inputs.major }}'
$FileContents = $FileContents -replace '"Minor": \d+', '"Minor": ${{ inputs.minor }}'
$FileContents = $FileContents -replace '"Patch": \d+', '"Patch": ${{ inputs.patch }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – task.loc.json
shell: pwsh
run: |-
$FilePath = 'src/task/task.loc.json'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace '"Major": \d+', '"Major": ${{ inputs.major }}'
$FileContents = $FileContents -replace '"Minor": \d+', '"Minor": ${{ inputs.minor }}'
$FileContents = $FileContents -replace '"Patch": \d+', '"Patch": ${{ inputs.patch }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – resources.resjson
shell: pwsh
run: |-
$FilePath = 'src/task/Strings/resources.resjson/en-US/resources.resjson'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace 'PR Metrics v\d+\.\d+\.\d+', 'PR Metrics v${{ env.version }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – gitHubReposInvoker.ts
shell: pwsh
run: |-
$FilePath = 'src/task/src/repos/gitHubReposInvoker.ts'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace 'PRMetrics\/v\d+\.\d+\.\d+', 'PRMetrics/v${{ env.version }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – gitHubReposInvoker.spec.ts
shell: pwsh
run: |-
$FilePath = 'src/task/tests/repos/gitHubReposInvoker.spec.ts'
$FileContents = Get-Content -Path $FilePath
$FileContents = $FileContents -replace 'PRMetrics\/v\d+\.\d+\.\d+', 'PRMetrics/v${{ env.version }}'
Set-Content -Path $FilePath -Value $FileContents
- name: Version Number – Increment Patch
id: increment-patch
shell: pwsh
run: |-
$IncrementedPatch = [int]::Parse(${{ inputs.patch }}) + 1
Write-Output -InputObject "INCREMENTED_PATCH=$IncrementedPatch" >> $Env:GITHUB_OUTPUT
- name: Version Number – release-phase-1.yml
shell: pwsh
run: |-
$FilePath = '.github/workflows/release-phase-1.yml'
$FileContents = Get-Content -Raw $FilePath
$FileContents = $FileContents -replace '(?<Yaml>major: )\d+', '${Yaml}${{ inputs.major }}'
$FileContents = $FileContents -replace '(?<Yaml>minor: )\d+', '${Yaml}${{ inputs.minor }}'
$FileContents = $FileContents -replace '(?<Yaml>patch: )\d+', '${Yaml}${{ steps.increment-patch.outputs.INCREMENTED_PATCH }}'
Set-Content -Path $FilePath -Value $FileContents.Substring(0, $FileContents.Length - 1) # Remove the trailing newline.
- name: Update LICENSE.txt
shell: pwsh
run: |-
$FilePath = 'src/LICENSE.txt'
$FileContents = Get-Content -Path $FilePath
$Index = [Array]::IndexOf($FileContents, ($FileContents | Where-Object { $_ -match 'NOTICES AND INFORMATION' }))
$Index -= 1
$FileContents = $FileContents[0..$Index]
Set-Content -Path $FilePath -Value $FileContents
- name: Git – Setup Authentication
run: gh auth setup-git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Git – Set Name
run: git config --global user.name "github-actions[bot]"
- name: Git – Set Email
run: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Git – Create Branch
run: git checkout -b release/v${{ env.version }}
- name: Git – Add Changed Files
run: git add -A
- name: Git – Commit Changed Files
run: git commit -m "Updating version number"
- name: Git – Push Changed Files
run: git push --set-upstream origin release/v${{ env.version }}
- name: PR – Create
run: >-
gh pr create
--title "[Autogenerated] Release v${{ env.version }}"
--body "Autogenerated release for PR Metrics v${{ env.version }}. This includes the latest dependency updates."
--label "release"
--assignee "${{ github.actor }}"
--reviewer "${{ github.actor }}"
env:
# Fine-grained Personal Access Token (PAT) with the following permissions for microsoft/PR-Metrics:
# - Read access to Metadata
# - Read and Write access to Pull Requests
GITHUB_TOKEN: ${{ secrets.RELEASE_PHASE_1_PR_CREATE }}
- name: PR – Comment
run: gh pr comment --body-file "./.github/workflows/support/release-phase-1-comment.md"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: npm – Install Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20.16.0
- name: npm – Update Dependencies
run: npx ncu -u
- name: npm – Update Transitive Dependencies
run: npm run update:package
- name: Git – Add Changed Files
run: git add -A
- name: Git – Commit Changed Files
run: git commit -m "Updating dependencies"
- name: Git – Pull Changed Files
run: git pull
- name: Git – Push Changed Files
run: git push --set-upstream origin release/v${{ env.version }}