Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[repo] Release process tweaks & improvements 4 #5598

Merged
merged 46 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6477db4
First version of prepare release workflow.
CodeBlanch May 4, 2024
f53d3c0
Permissions tweak.
CodeBlanch May 4, 2024
c7d4acf
Tweak.
CodeBlanch May 4, 2024
ad57c9d
Fix.
CodeBlanch May 4, 2024
c85b470
Fix.
CodeBlanch May 4, 2024
f7425e9
Add debug info.
CodeBlanch May 4, 2024
a866058
Tweak debug.
CodeBlanch May 4, 2024
aa71f11
Tweak.
CodeBlanch May 4, 2024
54ebd3a
Tweak.
CodeBlanch May 4, 2024
e1e7e27
Comment tweaks.
CodeBlanch May 5, 2024
513b779
Update RELEASING doc.
CodeBlanch May 5, 2024
e02111f
Tweaks.
CodeBlanch May 5, 2024
b8d4fa9
Tweak.
CodeBlanch May 6, 2024
cb3972d
Tweak.
CodeBlanch May 6, 2024
6a40ca2
Fix.
CodeBlanch May 6, 2024
f8527f2
Prepare repo to release core-1.9.0-alpha.1. (#26)
github-actions[bot] May 6, 2024
15123dd
Revert "Prepare repo to release core-1.9.0-alpha.1. (#26)"
CodeBlanch May 6, 2024
977b54c
Tweak.
CodeBlanch May 6, 2024
88f5299
Fix.
CodeBlanch May 6, 2024
14117d4
Tweak.
CodeBlanch May 6, 2024
dac47c5
Tweaks.
CodeBlanch May 6, 2024
134d043
Fixes.
CodeBlanch May 6, 2024
6773372
Fix.
CodeBlanch May 6, 2024
448b7bd
Tweaks.
CodeBlanch May 6, 2024
a694e95
Doc updates.
CodeBlanch May 7, 2024
6cbbd93
Merge from main.
CodeBlanch May 7, 2024
4531a54
Update post release PR for workflow call.
CodeBlanch May 7, 2024
de51d2f
Tweaks and fixes.
CodeBlanch May 8, 2024
875cb38
Fix.
CodeBlanch May 8, 2024
835fa88
Fix.
CodeBlanch May 8, 2024
e60a330
Fix.
CodeBlanch May 8, 2024
ff8716f
Lint.
CodeBlanch May 8, 2024
c7e75ce
Lint.
CodeBlanch May 8, 2024
1b4a521
Merge branch 'main' into repo-release-tweaks4
CodeBlanch May 8, 2024
ee4d78d
Tweak.
CodeBlanch May 8, 2024
f530065
Restore git checkout.
CodeBlanch May 8, 2024
a5e7ae3
Merge remote-tracking branch 'upstream/main' into repo-release-tweaks4
CodeBlanch May 9, 2024
75d4588
Code review.
CodeBlanch May 9, 2024
891d23a
Script injection fixes.
CodeBlanch May 11, 2024
a09cd1d
Post notice tag link fix.
CodeBlanch May 11, 2024
326e28e
Merge remote-tracking branch 'upstream/main' into repo-release-tweaks4
CodeBlanch May 13, 2024
a0dbb20
Move release scripts under new folder.
CodeBlanch May 13, 2024
393eb64
Refactor inline scripts into a module (#48)
CodeBlanch May 13, 2024
bdae881
Update .markdownlint.yaml
CodeBlanch May 13, 2024
b55f853
Merge branch 'main' into repo-release-tweaks4
CodeBlanch May 13, 2024
125a3ce
Tweak.
CodeBlanch May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 255 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
name: Prepare for a release

on:
workflow_dispatch:
inputs:
tag-prefix:
type: choice
options:
- core-
- coreunstable-
description: 'Release tag prefix'
required: true
version:
type: string
description: 'Release version'
required: true

pull_request:
types:
- closed

issue_comment:
types:
- created

permissions:
contents: write
pull-requests: write

jobs:
prepare-release-pr:
if: github.event_name == 'workflow_dispatch'

runs-on: windows-latest

steps:
- name: check out code
uses: actions/checkout@v4

- name: Create GitHub Pull Request to prepare release
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git switch --create release/prepare-${{ inputs.tag-prefix }}${{ inputs.version }}-release 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git switch failure'
Return
}

$body =
@"
Note: This PR was opened automatically by the [prepare release workflow](https://github.com/${{ github.repository }}/actions/workflows/prepare-release.yml).

## Changes

* CHANGELOG files updated for projects being released.
"@

# Update CHANGELOGs
& ./build/scripts/update-changelogs.ps1 -minVerTagPrefix "${{ inputs.tag-prefix }}" -version "${{ inputs.version }}"

# Update publicApi files for stable releases
if ("${{ inputs.version }}" -notlike "*-alpha*" -and "${{ inputs.version }}" -notlike "*-beta*" -and "${{ inputs.version }}" -notlike "*-rc*")
{
& ./build/scripts/finalize-publicapi.ps1 -minVerTagPrefix "${{ inputs.tag-prefix }}"

$body += "`r`n* Public API files updated for projects being released (only performed for stable releases)."
}

git commit -a -m "Prepare repo to release ${{ inputs.tag-prefix }}${{ inputs.version }}." 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git commit failure'
Return
}

git push -u origin release/prepare-${{ inputs.tag-prefix }}${{ inputs.version }}-release 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git push failure'
Return
}

gh pr create `
--title "[repo] Prepare release ${{ inputs.tag-prefix }}${{ inputs.version }}" `
--body $body `
--base ${{ github.ref_name }} `
--head release/prepare-${{ inputs.tag-prefix }}${{ inputs.version }}-release `
--label infra
env:
GH_TOKEN: ${{ github.token }}

lock-pr-and-post-notice-to-create-release-tag:
if: |
github.event_name == 'pull_request'
&& github.event.action == 'closed'
&& github.event.pull_request.user.login == 'github-actions[bot]'
&& github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.title, '[repo] Prepare release ')

runs-on: windows-latest

env:
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}

steps:
- name: check out code
uses: actions/checkout@v4

- name: Lock GitHub Pull Request to prepare release
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

$match = [regex]::Match($env:PULL_REQUEST_TITLE, '^\[repo\] Prepare release (.*)$')
if ($match.Success -eq $false)
{
Write-Error 'Could not parse tag from PR title'
Return
}

$tag = $match.Groups[1].Value

git tag -a $tag -m "$tag" $prViewResponse.mergeCommit.oid 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git tag failure'
Return
}

$body =
@"
I noticed this PR was merged.

Post a comment with "/CreateReleaseTag" in the body if you would like me to create the release tag ``$tag`` for [the merge commit](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.merge_commit_sha }}) and then trigger the package workflow.
"@

gh pr comment ${{ github.event.pull_request.number }} `
--body $body

gh pr lock ${{ github.event.pull_request.number }}
env:
GH_TOKEN: ${{ github.token }}

create-release-tag-unlock-pr-post-notice:
if: |
github.event_name == 'issue_comment'
&& github.event.issue.pull_request
&& github.event.issue.locked == true
&& contains(github.event.comment.body, '/CreateReleaseTag')
&& startsWith(github.event.issue.title, '[repo] Prepare release ')
&& github.event.issue.pull_request.merged_at

runs-on: windows-latest

env:
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}

outputs:
tag: ${{ steps.create-tag.outputs.tag }}

steps:
- name: check out code
uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit which fails the git tag operation below
fetch-depth: 0

- name: Create release tag
id: create-tag
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

$prViewResponse = gh pr view ${{ github.event.issue.number }} --json mergeCommit,author | ConvertFrom-Json

if ($prViewResponse.author.is_bot -eq $false -or $prViewResponse.author.login -ne 'app/github-actions')
{
Write-Error 'PR author was unexpected'
Return
}

$match = [regex]::Match($env:PULL_REQUEST_TITLE, '^\[repo\] Prepare release (.*)$')
if ($match.Success -eq $false)
{
Write-Error 'Could not parse tag from PR title'
Return
}

$tag = $match.Groups[1].Value

git tag -a $tag -m "$tag" $prViewResponse.mergeCommit.oid 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git tag failure'
Return
}

git push origin $tag 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git push failure'
Return
}

gh pr unlock ${{ github.event.issue.number }}

$body =
@"
I just pushed the [$tag](https://github.com/${{ github.repository }}/releases/tag/$tag) tag.

The [package workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) should begin momentarily.
"@

gh pr comment ${{ github.event.issue.number }} `
--body $body

echo "tag=$tag" >> $env:GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}

invoke-package-workflow:
needs: create-release-tag-unlock-pr-post-notice
uses: ./.github/workflows/publish-packages-1.0.yml
with:
tag: ${{ needs.create-release-tag-unlock-pr-post-notice.outputs.tag }}

post-packages-ready-notice:
needs:
- create-release-tag-unlock-pr-post-notice
- invoke-package-workflow
runs-on: windows-latest
steps:
- name: check out code
uses: actions/checkout@v4

- name: Post notice when packages are ready
shell: pwsh
run: |
$body =
@"
The packages for [${{ needs.create-release-tag-unlock-pr-post-notice.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-release-tag-unlock-pr-post-notice.outputs.tag }}) are now available: ${{ needs.invoke-package-workflow.outputs.artifact-url }}.

Have a nice day!
"@

gh pr comment ${{ github.event.issue.number }} `
--body $body
env:
GH_TOKEN: ${{ github.token }}
Loading