Add workflow for creating versioning pr #148
Workflow file for this run
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
name: Build, test and release | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
version: | |
name: Get versioning information | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.get_version.outputs.version }} | |
next_release_version: ${{ steps.get_next_release_version.outputs.version }} | |
create_release: ${{ steps.set_create_release.outputs.create_release }} | |
has_unreleased_changes: ${{ steps.set_has_unreleased_changes.outputs.has_unreleased_changes }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Get all tags | |
- name: Download auto | |
run: | | |
curl -kL -o - https://github.com/intuit/auto/releases/download/v11.3.0/auto-linux.gz | gunzip > ${{ runner.temp }}/auto | |
chmod +x ${{ runner.temp }}/auto | |
- name: Test latest | |
run: ${{ runner.temp }}/auto latest --dry-run --no-version-prefix --name github-actions[bot] --email github-actions[bot]@users.noreply.github.com | |
- name: Get next release version | |
id: get_next_release_version | |
run: echo "version=$(${{ runner.temp }}/auto latest --dry-run --quiet --no-version-prefix --name github-actions[bot] --email github-actions[bot]@users.noreply.github.com)" >> $GITHUB_OUTPUT | |
- name: Print next release version | |
run: echo "${{ steps.get_next_release_version.outputs.version }}" | |
- name: Get next release semver bump type | |
id: get_next_release_semver_bump_type | |
run: echo "bump_type=$(${{ runner.temp }}/auto version --only-publish-with-release-label)" >> $GITHUB_OUTPUT | |
- name: Print next release semver bump type | |
run: echo "${{ steps.get_next_release_semver_bump_type.outputs.bump_type }}" | |
- name: Get branch names | |
id: branch_names | |
uses: OctopusDeploy/util-actions/[email protected] | |
- name: Get pre-release version when next release version does not exist | |
id: get_pre_release_version | |
uses: paulhatch/[email protected] | |
with: | |
tag_prefix: "v" | |
version_format: "${major}.${minor}.${patch}-${{ steps.branch_names.outputs.branch_name }}.${{ github.run_number }}-${{ github.run_attempt }}" | |
- name: Get pre-release version when next release version exists | |
id: get_specific_pre_release_version | |
run: echo "version=${{ steps.get_next_release_version.outputs.version }}-${{ steps.branch_names.outputs.branch_name }}.${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_OUTPUT | |
- name: Set whether to perform a release | |
id: set_create_release | |
run: echo "create_release=${{ steps.get_next_release_semver_bump_type.outputs.bump_type != '' }}" >> $GITHUB_OUTPUT | |
- name: Set whether there are unreleased changes | |
id: set_has_unreleased_changes | |
run: echo "has_unreleased_changes=${{ steps.get_next_release_semver_bump_type.outputs.bump_type == '' && steps.get_next_release_version.outputs.version != '' }}" >> $GITHUB_OUTPUT | |
- name: Get version | |
id: get_version | |
run: echo "version=${{ steps.set_create_release.outputs.create_release == 'true' && steps.get_next_release_version.outputs.version || steps.get_next_release_version.outputs.version != '' && steps.get_specific_pre_release_version.outputs.version || steps.get_pre_release_version.outputs.version }}" >> $GITHUB_OUTPUT | |
- name: Print version | |
run: echo "Version ${{ steps.get_version.outputs.version }}" | |
build: | |
needs: version | |
strategy: | |
matrix: | |
include: | |
- name: Linux | |
os: ubuntu-latest | |
- name: Windows | |
os: windows-latest | |
- name: macOS | |
os: macos-latest | |
name: Build and test on ${{ matrix.name }} | |
runs-on: ${{ matrix.os }} | |
defaults: | |
run: | |
working-directory: src | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --no-restore -c Release | |
- name: Test | |
run: dotnet test --no-build -c Release --verbosity normal --logger "trx;LogFileName=${{ github.workspace }}/tests/test_results.trx" | |
- name: Create test report | |
uses: phoenix-actions/test-reporting@v15 | |
if: success() || failure() # run this step even if previous step failed | |
with: | |
name: Tests | |
path: ${{ github.workspace }}/tests/*.trx | |
path-replace-backslashes: true # Required for Windows paths | |
reporter: dotnet-trx | |
output-to: step-summary | |
publish: | |
needs: [version, build] | |
strategy: | |
matrix: | |
include: | |
- name: Linux amd64 | |
runtime-id: linux-x64 | |
artifact-name: linux_amd64 | |
archive_type: tar | |
- name: Linux arm64 | |
runtime-id: linux-arm64 | |
artifact-name: linux_arm64 | |
archive_type: tar | |
- name: Windows amd64 | |
runtime-id: win-x64 | |
artifact-name: windows_amd64 | |
archive_type: zip | |
- name: Windows arm64 | |
runtime-id: win-arm64 | |
artifact-name: windows_arm64 | |
archive_type: zip | |
- name: macOS amd64 | |
runtime-id: osx-x64 | |
artifact-name: macos_amd64 | |
archive_type: tar | |
- name: macOS arm64 | |
runtime-id: osx-arm64 | |
artifact-name: macos_arm64 | |
archive_type: tar | |
name: Publish ${{ matrix.name }} | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: src | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
- name: Publish | |
run: dotnet publish Stack/Stack.csproj -c Release -r ${{ matrix.runtime-id }} -p:Version=${{ needs.version.outputs.version }} -p:DebugType=None -p:DebugSymbols=false -o ${{ github.workspace }}/publish | |
- run: mkdir -p ${{ github.workspace }}/artifacts | |
- name: Create tar.gz arhive | |
run: tar -czf ${{ github.workspace }}/artifacts/stack_${{ needs.version.outputs.version }}_${{ matrix.artifact-name }}.tar.gz * | |
working-directory: ${{ github.workspace }}/publish | |
if: matrix.archive_type == 'tar' | |
- name: Create zip arhive | |
run: zip -r ${{ github.workspace }}/artifacts/stack_${{ needs.version.outputs.version }}_${{ matrix.artifact-name }}.zip * | |
working-directory: ${{ github.workspace }}/publish | |
if: matrix.archive_type == 'zip' | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
overwrite: true | |
name: ${{ matrix.artifact-name }} | |
path: ${{ github.workspace }}/artifacts/* | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
needs: [version, publish] | |
if: github.ref == 'refs/heads/main' && needs.version.outputs.create_release == 'true' | |
permissions: | |
contents: write | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Get all tags | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ${{ github.workspace }}/artifacts | |
- name: List artifacts | |
run: ls -lR ${{ github.workspace }}/artifacts | |
- name: Download auto | |
run: | | |
curl -kL -o - https://github.com/intuit/auto/releases/download/v11.3.0/auto-linux.gz | gunzip > ${{ runner.temp }}/auto | |
chmod +x ${{ runner.temp }}/auto | |
- name: Release | |
run: ${{ runner.temp }}/auto shipit --only-publish-with-release-label --no-changelog --name github-actions[bot] --email github-actions[bot]@users.noreply.github.com | |
versioning_pr: | |
name: Create versioning pull request | |
needs: [version, publish] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
if: github.ref == 'refs/heads/main' && needs.version.outputs.has_unreleased_changes == 'true' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Get all tags | |
- name: Download auto | |
run: | | |
curl -kL -o - https://github.com/intuit/auto/releases/download/v11.3.0/auto-linux.gz | gunzip > ${{ runner.temp }}/auto | |
chmod +x ${{ runner.temp }}/auto | |
- name: Update changelog | |
id: update_changelog | |
run: | | |
echo "changes<<EOF" >> $GITHUB_ENV | |
echo "$(${{ runner.temp }}/auto changelog --quiet --no-git-commit --name github-actions[bot] --email github-actions[bot]@users.noreply.github.com)" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Create versioning pull request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
branch: auto/release | |
title: Release version `${{ needs.get_version.outputs.next_release_version }}` | |
commit-message: Release version `${{ needs.get_version.outputs.next_release_version }}` | |
labels: release | |
body: | | |
This PR will release version `${{ needs.get_version.outputs.next_release_version }}` | |
## Changes | |
${{ env.changes }} | |
## Releasing a new version | |
To release the version when you are ready, merge this PR. The new version will then be built and published to a GitHub release. | |
If you don't see your changes in the list above, please check your PR is tagged with an appropriate label to include your change in the release notes. |