Skip to content

Commit

Permalink
Add automation scripts for metadata and version management
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-edmondson committed Jan 2, 2025
1 parent 3c76580 commit df6f72d
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 193 deletions.
200 changes: 7 additions & 193 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,207 +73,21 @@ jobs:
$global:LASTEXITCODE = 0
- name: Generate Version
- name: Make Version
shell: pwsh
run: |
# find the last version that was released
$LAST_TAG = (git tag --list --sort=-v:refname)[0]
$LAST_VERSION = $LAST_TAG -replace 'v', ''
$IS_PRERELEASE = $LAST_VERSION.Contains('-')
$LAST_VERSION = $LAST_VERSION -replace '-alpha', ''
$LAST_VERSION = $LAST_VERSION -replace '-beta', ''
$LAST_VERSION = $LAST_VERSION -replace '-rc', ''
$LAST_VERSION = $LAST_VERSION -replace '-pre', ''
if ($LAST_VERSION -eq '') {
$LAST_VERSION = '1.0.0-pre.0'
}
$LAST_VERSION_COMPONENTS = $LAST_VERSION -split '\.'
$LAST_VERSION_MAJOR = [int]$LAST_VERSION_COMPONENTS[0]
$LAST_VERSION_MINOR = [int]$LAST_VERSION_COMPONENTS[1]
$LAST_VERSION_PATCH = [int]$LAST_VERSION_COMPONENTS[2]
$LAST_VERSION_PRERELEASE = 0
if ($LAST_VERSION_COMPONENTS.Length -gt 3) {
$LAST_VERSION_PRERELEASE = [int]$LAST_VERSION_COMPONENTS[3]
}
# calculate which increment is needed
$EXCLUDE_BOTS = '^(?!.*(\[bot\]|github|ProjectDirector|SyncFileContents)).*$'
$EXCLUDE_HIDDEN_FILES = ":(icase,exclude)*/.*"
$EXCLUDE_MARKDOWN_FILES = ":(icase,exclude)*/*.md"
$EXCLUDE_TEXT_FILES = ":(icase,exclude)*/*.txt"
$EXCLUDE_SOLUTIONS_FILES = ":(icase,exclude)*/*.sln"
$EXCLUDE_PROJECTS_FILES = ":(icase,exclude)*/*.*proj"
$EXCLUDE_URL_FILES = ":(icase,exclude)*/*.url"
$EXCLUDE_BUILD_FILES = ":(icase,exclude)*/Directory.Build.*"
$EXCLUDE_CI_FILES = ":(icase,exclude).github/workflows/*"
$INCLUDE_ALL_FILES = "*/*.*"
$FIRST_COMMIT = (git rev-list HEAD)[-1]
$LAST_COMMIT = '${{ github.sha }}'
$COMMITS = "$FIRST_COMMIT...$LAST_COMMIT"
$LAST_PATCH_COMMIT = git log -n 1 --perl-regexp --regexp-ignore-case --format=format:%H --committer="$EXCLUDE_BOTS" --author="$EXCLUDE_BOTS" $COMMITS
$LAST_MINOR_COMMIT = git log -n 1 --perl-regexp --regexp-ignore-case --format=format:%H --committer="$EXCLUDE_BOTS" --author="$EXCLUDE_BOTS" $COMMITS `
-- `
$INCLUDE_ALL_FILES `
$EXCLUDE_HIDDEN_FILES `
$EXCLUDE_MARKDOWN_FILES `
$EXCLUDE_TEXT_FILES `
$EXCLUDE_SOLUTIONS_FILES `
$EXCLUDE_PROJECTS_FILES `
$EXCLUDE_URL_FILES `
$EXCLUDE_BUILD_FILES `
$EXCLUDE_CI_FILES
$VERSION_INCREMENT = 'prerelease'
if ($LAST_COMMIT -eq $LAST_PATCH_COMMIT) {
$VERSION_INCREMENT = 'patch'
}
if ($LAST_COMMIT -eq $LAST_MINOR_COMMIT) {
$VERSION_INCREMENT = 'minor'
}
if ($IS_PRERELEASE) {
if ($VERSION_INCREMENT -eq 'prerelease') {
$NEW_PRERELEASE = $LAST_VERSION_PRERELEASE + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$LAST_VERSION_PATCH-pre.$NEW_PRERELEASE"
} elseif ($VERSION_INCREMENT -eq 'patch') {
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$LAST_VERSION_PATCH"
}
} else {
if ($VERSION_INCREMENT -eq 'prerelease') {
$NEW_PATCH = $LAST_VERSION_PATCH + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$NEW_PATCH-pre.1"
} elseif ($VERSION_INCREMENT -eq 'patch') {
$NEW_PATCH = $LAST_VERSION_PATCH + 1
$VERSION = "$LAST_VERSION_MAJOR.$LAST_VERSION_MINOR.$NEW_PATCH"
}
}
if ($VERSION_INCREMENT -eq 'minor') {
$NEW_MINOR = $LAST_VERSION_MINOR + 1
$VERSION = "$LAST_VERSION_MAJOR.$NEW_MINOR.0"
}
# Output the version information
Write-Host "LAST_VERSION: $LAST_VERSION"
Write-Host "LAST_VERSION_MAJOR: $LAST_VERSION_MAJOR"
Write-Host "LAST_VERSION_MINOR: $LAST_VERSION_MINOR"
Write-Host "LAST_VERSION_PATCH: $LAST_VERSION_PATCH"
Write-Host "LAST_VERSION_PRERELEASE: $LAST_VERSION_PRERELEASE"
Write-Host "IS_PRERELEASE: $IS_PRERELEASE"
Write-Host "FIRST_COMMIT: $FIRST_COMMIT"
Write-Host "LAST_COMMIT: $LAST_COMMIT"
Write-Host "LAST_PATCH_COMMIT: $LAST_PATCH_COMMIT"
Write-Host "LAST_MINOR_COMMIT: $LAST_MINOR_COMMIT"
Write-Host "VERSION_INCREMENT: $VERSION_INCREMENT"
Write-Host "VERSION: $VERSION"
# set the environment variables
"LAST_VERSION=$LAST_VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_MAJOR=$LAST_VERSION_MAJOR" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_MINOR=$LAST_VERSION_MINOR" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_PATCH=$LAST_VERSION_PATCH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_VERSION_PRERELEASE=$LAST_VERSION_PRERELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IS_PRERELEASE=$IS_PRERELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"FIRST_COMMIT=$FIRST_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_COMMIT=$LAST_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_PATCH_COMMIT=$LAST_PATCH_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"LAST_MINOR_COMMIT=$LAST_MINOR_COMMIT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"VERSION_INCREMENT=$VERSION_INCREMENT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"VERSION=$VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
run: scripts/make-version.ps1 "${{ github.sha }}"

# output files
$VERSION | Out-File -FilePath VERSION.md -Encoding utf8
$global:LASTEXITCODE = 0
- name: Generate License
- name: Make License
shell: pwsh
run: |
$AUTHORS = '${{ github.repository_owner }}'.Replace('-', '.') + ' contributors'
$COPYRIGHT = "Copyright (c) 2023-$(Get-Date -Format 'yyyy') $AUTHORS"
$PROJECT_URL = "${{ github.server_url }}/${{ github.repository }}"
$AUTHORS_URL = "${{ github.server_url }}/${{ github.repository_owner }}"
$LICENSE = @"
MIT License
$PROJECT_URL
$COPYRIGHT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the `"Software`"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED `"AS IS`", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"@
# output files
$LICENSE | Out-File -FilePath LICENSE.md -Encoding utf8
$AUTHORS | Out-File -FilePath AUTHORS.md -Encoding utf8
$COPYRIGHT | Out-File -FilePath COPYRIGHT.md -Encoding utf8
$PROJECT_URL | Out-File -FilePath PROJECT_URL.url -Encoding utf8
$AUTHORS_URL | Out-File -FilePath AUTHORS.url -Encoding utf8
# output the metadata
Write-Host "AUTHORS: $AUTHORS"
Write-Host "COPYRIGHT: $COPYRIGHT"
Write-Host "LICENSE: $LICENSE"
Write-Host "PROJECT_URL: $PROJECT_URL"
Write-Host "AUTHORS_URL: $AUTHORS_URL"
run: scripts/make-license.ps1 "${{ github.server_url }}" "${{ github.repository_owner }}" "${{ github.repository }}"

# set the environment variables
"AUTHORS=$AUTHORS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"COPYRIGHT=$COPYRIGHT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"PROJECT_URL=$PROJECT_URL" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"AUTHORS_URL=$AUTHORS_URL" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$global:LASTEXITCODE = 0
- name: Generate Changelog
- name: Make Changelog
shell: pwsh
run: |
$CHANGELOG = ""
$CHANGELOG += "## $VERSION"
Write-Host "CHANGELOG: $CHANGELOG"
"CHANGELOG=$CHANGELOG" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$CHANGELOG | Out-File -FilePath CHANGELOG.md -Encoding utf8
$global:LASTEXITCODE = 0
run: scripts/make-changelog.ps1 "${{ env.VERSION }}" "${{ github.sha }}"

- name: Commit Metadata
shell: pwsh
run: |
git config --global user.name "Github Actions"
git config --global user.email "actions@users.noreply.github.com"
git add VERSION.md LICENSE.md AUTHORS.md COPYRIGHT.md CHANGELOG.md PROJECT_URL.url AUTHORS.url
git commit -m "[bot][skip ci] Update Metadata"
git push
$RELEASE_HASH = (git rev-parse HEAD)
Write-Host "RELEASE_HASH: $RELEASE_HASH"
"RELEASE_HASH=$RELEASE_HASH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
run: scripts/commit-metadata.ps1

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Add issues and prs to ktsu.dev project

on:
issues:
types:
- opened
- reopened
- transferred
- labeled
pull_request:
types:
- opened
- reopened
- labeled

jobs:
add-to-project:
name: Add to project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v1.0.2
with:
project-url: https://github.com/orgs/ktsu-dev/projects/2
github-token: ${{ secrets.PROJECT_AUTOMATION_TOKEN }}
9 changes: 9 additions & 0 deletions scripts/commit-metadata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
git config --global user.name "Github Actions"
git config --global user.email "actions@users.noreply.github.com"
git add VERSION.md LICENSE.md AUTHORS.md COPYRIGHT.md CHANGELOG.md PROJECT_URL.url AUTHORS.url
git commit -m "[bot][skip ci] Update Metadata"
git push

$RELEASE_HASH = (git rev-parse HEAD)
Write-Host "RELEASE_HASH: $RELEASE_HASH"
"RELEASE_HASH=$RELEASE_HASH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Loading

0 comments on commit df6f72d

Please sign in to comment.