-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Actions workflows to automate releases.
- Loading branch information
1 parent
1ad7564
commit cdb01c7
Showing
3 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
name: bump-version | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'The optional version string for the next release.' | ||
required: false | ||
type: string | ||
default: '' | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
bump-version: | ||
runs-on: [ ubuntu-latest ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
|
||
steps: | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | ||
with: | ||
token: ${{ secrets.COSTELLOBOT_TOKEN }} | ||
|
||
- name: Bump version | ||
id: bump-version | ||
shell: pwsh | ||
env: | ||
NEXT_VERSION: ${{ inputs.version }} | ||
run: | | ||
$properties = Join-Path "." "Directory.Build.props" | ||
$xml = [xml](Get-Content $properties) | ||
$versionPrefix = $xml.SelectSingleNode('Project/PropertyGroup/VersionPrefix') | ||
if (-Not [string]::IsNullOrEmpty(${env:NEXT_VERSION})) { | ||
$version = [System.Version]::new(${env:NEXT_VERSION}) | ||
$assemblyVersionProperty = $xml.SelectSingleNode('Project/PropertyGroup/AssemblyVersion') | ||
$assemblyVersion = [System.Version]::new($version.Major, ($version.Major -eq 0 ? $version.Minor : 0), 0, 0) | ||
$assemblyVersionProperty.InnerText = $assemblyVersion.ToString() | ||
} else { | ||
$version = [System.Version]::new($versionPrefix.InnerText) | ||
$version = [System.Version]::new($version.Major, $version.Minor, $version.Build + 1) | ||
} | ||
$updatedVersion = $version.ToString() | ||
$versionPrefix.InnerText = $updatedVersion | ||
$settings = New-Object System.Xml.XmlWriterSettings | ||
$settings.Encoding = New-Object System.Text.UTF8Encoding($false) | ||
$settings.Indent = $true | ||
$settings.OmitXmlDeclaration = $true | ||
$writer = [System.Xml.XmlWriter]::Create($properties, $settings) | ||
$xml.Save($writer) | ||
$writer.Flush() | ||
$writer.Close() | ||
$writer = $null | ||
"" >> $properties | ||
"version=${updatedVersion}" >> $env:GITHUB_OUTPUT | ||
- name: Push changes to GitHub | ||
id: push-changes | ||
shell: pwsh | ||
env: | ||
GIT_COMMIT_USER_EMAIL: ${{ vars.GIT_COMMIT_USER_EMAIL }} | ||
GIT_COMMIT_USER_NAME: ${{ vars.GIT_COMMIT_USER_NAME }} | ||
NEXT_VERSION: ${{ steps.bump-version.outputs.version }} | ||
run: | | ||
$gitStatus = (git status --porcelain) | ||
if ([string]::IsNullOrEmpty($gitStatus)) { | ||
throw "No changes to commit." | ||
} | ||
git config color.diff always | ||
git --no-pager diff | ||
$branchName = "bump-version-${env:NEXT_VERSION}" | ||
git config user.email ${env:GIT_COMMIT_USER_EMAIL} | Out-Null | ||
git config user.name ${env:GIT_COMMIT_USER_NAME} | Out-Null | ||
git fetch origin --no-tags | Out-Null | ||
git rev-parse --verify --quiet "remotes/origin/${branchName}" | Out-Null | ||
if ($LASTEXITCODE -eq 0) { | ||
Write-Host "Branch ${branchName} already exists." | ||
exit 0 | ||
} | ||
git checkout -b $branchName | ||
git add . | ||
git commit -m "Bump version`n`nBump version to ${env:NEXT_VERSION} for the next release." | ||
git push -u origin $branchName | ||
"branch-name=${branchName}" >> $env:GITHUB_OUTPUT | ||
"updated-version=true" >> $env:GITHUB_OUTPUT | ||
"version=${env:NEXT_VERSION}" >> $env:GITHUB_OUTPUT | ||
- name: Create pull request | ||
if: steps.push-changes.outputs.updated-version == 'true' | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
env: | ||
BASE_BRANCH: ${{ github.event.repository.default_branch }} | ||
HEAD_BRANCH: ${{ steps.push-changes.outputs.branch-name }} | ||
NEXT_VERSION: ${{ steps.push-changes.outputs.version }} | ||
with: | ||
github-token: ${{ secrets.COSTELLOBOT_TOKEN }} | ||
script: | | ||
const nextVersion = process.env.NEXT_VERSION; | ||
const { repo, owner } = context.repo; | ||
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`; | ||
const { data: pr } = await github.rest.pulls.create({ | ||
title: 'Bump version', | ||
owner, | ||
repo, | ||
head: process.env.HEAD_BRANCH, | ||
base: process.env.BASE_BRANCH, | ||
draft: true, | ||
body: [ | ||
`Bump version to \`${nextVersion}\` for the next release.`, | ||
'', | ||
`This pull request was generated by [GitHub Actions](${workflowUrl}).` | ||
].join('\n') | ||
}); | ||
core.notice(`Created pull request ${owner}/${repo}#${pr.number}: ${pr.html_url}`); | ||
try { | ||
const { data: milestones } = await github.rest.issues.listMilestones({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
}); | ||
const title = `v${nextVersion}`; | ||
let milestone = milestones.find((p) => p.title === title); | ||
if (!milestone) { | ||
const created = await github.rest.issues.createMilestone({ | ||
owner, | ||
repo, | ||
title, | ||
}); | ||
milestone = created.data; | ||
} | ||
await github.rest.issues.update({ | ||
owner, | ||
repo, | ||
issue_number: pr.number, | ||
milestone: milestone.number | ||
}); | ||
} catch (error) { | ||
// Ignore | ||
} | ||
close-milestone: | ||
runs-on: [ ubuntu-latest ] | ||
if: github.event_name == 'release' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
|
||
steps: | ||
|
||
- name: Close milestone | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
env: | ||
RELEASE_DATE: ${{ github.event.release.published_at }} | ||
RELEASE_VERSION: ${{ github.event.release.tag_name }} | ||
with: | ||
github-token: ${{ secrets.COSTELLOBOT_TOKEN }} | ||
script: | | ||
const { repo, owner } = context.repo; | ||
const { data: milestones } = await github.rest.issues.listMilestones({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
}); | ||
const milestone = milestones.find((p) => p.title === process.env.RELEASE_VERSION); | ||
if (!milestone) { | ||
return; | ||
} | ||
try { | ||
await github.rest.issues.updateMilestone({ | ||
owner, | ||
repo, | ||
milestone_number: milestone.number, | ||
state: 'closed', | ||
due_on: process.env.RELEASE_DATE, | ||
}); | ||
} catch (error) { | ||
// Ignore | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
publish: | ||
description: 'If true, does not create the release as a draft.' | ||
required: false | ||
type: boolean | ||
default: false | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
release: | ||
runs-on: [ ubuntu-latest ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
|
||
steps: | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | ||
with: | ||
token: ${{ secrets.COSTELLOBOT_TOKEN }} | ||
|
||
- name: Get version | ||
id: get-version | ||
shell: pwsh | ||
run: | | ||
$properties = Join-Path "." "Directory.Build.props" | ||
$xml = [xml](Get-Content $properties) | ||
$version = $xml.SelectSingleNode('Project/PropertyGroup/VersionPrefix').InnerText | ||
"version=${version}" >> $env:GITHUB_OUTPUT | ||
- name: Create release | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
env: | ||
DRAFT: ${{ inputs.publish != true }} | ||
VERSION: ${{ steps.get-version.outputs.version }} | ||
with: | ||
github-token: ${{ secrets.COSTELLOBOT_TOKEN }} | ||
script: | | ||
const { repo, owner } = context.repo; | ||
const draft = process.env.DRAFT === 'true'; | ||
const version = process.env.VERSION; | ||
const tag_name = `v${version}`; | ||
const name = tag_name; | ||
const { data: release } = await github.rest.repos.createRelease({ | ||
owner, | ||
repo, | ||
tag_name, | ||
name, | ||
draft: true, | ||
generate_release_notes: true, | ||
prerelease: true, | ||
}); | ||
const release_id = release.id; | ||
const body = release.body | ||
.split('\n') | ||
.filter((line) => !line.includes(' @costellobot ')) | ||
.filter((line) => !line.includes(' @dependabot ')) | ||
.join('\n'); | ||
const { data: updated } = await github.rest.repos.updateRelease({ | ||
owner, | ||
repo, | ||
release_id, | ||
draft, | ||
body, | ||
}); | ||
core.notice(`Created release ${updated.name}: ${updated.html_url}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters