move create_changelog to before build #202
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
#### Build, Test, and Publish CoseSignTool #### | |
#### This workflow runs on all platforms and handles two different types of builds: | |
# 1. Pull request builds: These are triggered by a pull request. They build and test the code, but do not publish or upload release artifacts. | |
# 2. Continuous integration builds: These are triggered by a push to the main branch. They build, test, create a semantically versioned release, generate a changelog, and publish zipped binaries to the new release. | |
# To update the Major, Minor, or Prerelease version, create a new Tag with the new version number. The next time a release is created, the version number will be updated. Only the repo owners should create tags. | |
# TODO: Lock down the perms on tag creation so only the repo owners can do it. | |
name: Build, Test, and Publish | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "*" ] | |
#release: # Turn this off once we are creating releases automatically | |
#types: [created] | |
jobs: | |
build: | |
name: build-${{matrix.os}} | |
needs: [ create_changelog ] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: windows-latest | |
dir_command: gci -Recurse | |
zip_command_debug: Compress-Archive -Path ./debug/ -DestinationPath CoseSignTool-Windows-debug.zip | |
zip_command_release: Compress-Archive -Path ./release/ -DestinationPath CoseSignTool-Windows-release.zip | |
- os: ubuntu-latest | |
dir_command: ls -a -R | |
zip_command_debug: zip -r CoseSignTool-Linux-debug.zip ./debug/ | |
zip_command_release: zip -r CoseSignTool-Linux-release.zip ./release/ | |
- os: macos-latest | |
dir_command: ls -a -R | |
zip_command_debug: zip -r CoseSignTool-MacOS-debug.zip ./debug/ | |
zip_command_release: zip -r CoseSignTool-MacOS-release.zip ./release/ | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 7.0.x | |
# Use the Dotnet Test command to load dependencies, build, and test the code. | |
- name: Build and Test debug | |
run: dotnet test --verbosity normal CoseSignTool/CoseSignTool.sln | |
- name: List working directory | |
run: ${{ matrix.dir_command }} | |
# Create a changelog that includes all the PRs merged since the last release. | |
# This has to happen in the PR build and not the release build so it can be committed to the current branch before it merges to Main. | |
create_changelog: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Generate changelog | |
uses: tj-actions/github-changelog-generator@v1.19 | |
with: | |
output: CHANGELOG.md | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit changelog | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git fetch | |
git checkout $GITHUB_HEAD_REF | |
git add CHANGELOG.md | |
if git diff-index --quiet HEAD; then | |
echo "No changes were logged." | |
else | |
git commit --allow-empty -m "Update changelog for release" | |
git push | |
fi | |
# git commit -m "Update changelog for release" | |
# git push | |
# If this is a pull request build, we're done. Otherwise: | |
# 1. Create a release. | |
# 2. Publish the binaries to ./published. | |
# 3. Zip the binaries. | |
# 4. Upload the zipped binaries to the release. | |
# Create a semantically versioned release. | |
create_release: | |
name: Create Release | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- name: Checkout code again # Probably not needed. | |
uses: actions/checkout@v2 | |
- name: Get merge message | |
run: | | |
echo "Try gettting the merge message from git log." | |
git log -1 --pretty=format:\"%s\" | |
echo "Merge message from env is ${{ github.event.head_commit.message }}" | |
# Create a semantically versioned tag using lastTag-COMMIT_COUNT-COMMIT_HASH, e.g., 1.2.3-32-hashvalue unless a new tag has been created manually. | |
# - name: Create SemVer tag | |
# id: auto_tag | |
# uses: DanySK/semver-autotag-action@master | |
# - name: Copy tag to local environment variable | |
# id: save_tag | |
# run: | | |
# TAG=$(git describe --tags --exact-match HEAD) | |
# echo "::set-output name=generated_tag::$TAG" | |
# echo ::set-env name=TAG::$TAG | |
# Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ | |
- name: Create SemVer tag # Maybe it will work now? | |
id: semver-tag # Output: ${{ steps.semver-tag.outputs.semver_tag }} | |
uses: wakatime/semver-action@v1.6.0 | |
with: | |
prefix: v | |
#repo_dir: ${{ github.workspace }} | |
main_branch_name: main | |
debug: true | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.semver-tag.outputs.semver_tag }} # If this doesn't work, use the github command. | |
release_name: Release ${{ steps.semver-tag.outputs.semver_tag }} | |
# This section will need tweaking once I see what the output looks like in context. | |
# Does it make sense to use body_path and point to the changelog instead? | |
# Or should I use the summary from the PR? | |
# body: | | |
# This is a new release. | |
body_path: ./CHANGELOG.md | |
draft: false | |
prerelease: ${{ steps.semver-tag.outputs.is_prerelease }} | |
release_assets: | |
name: release-assets | |
needs: [ build ] | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ${{ matrix.os }} | |
# env: # Can I declare this once for the whole job? | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
strategy: | |
matrix: # Can I re-use the matrix from the first job? | |
include: | |
- os: windows-latest | |
dir_command: gci -Recurse | |
zip_command_debug: Compress-Archive -Path ./debug/ -DestinationPath CoseSignTool-Windows-debug.zip | |
zip_command_release: Compress-Archive -Path ./release/ -DestinationPath CoseSignTool-Windows-release.zip | |
- os: ubuntu-latest | |
dir_command: ls -a -R | |
zip_command_debug: zip -r CoseSignTool-Linux-debug.zip ./debug/ | |
zip_command_release: zip -r CoseSignTool-Linux-release.zip ./release/ | |
- os: macos-latest | |
dir_command: ls -a -R | |
zip_command_debug: zip -r CoseSignTool-MacOS-debug.zip ./debug/ | |
zip_command_release: zip -r CoseSignTool-MacOS-release.zip ./release/ | |
steps: | |
# Not sure if we need to do this again - get this working then try without these steps here. | |
- name: Checkout code again | |
uses: actions/checkout@v3 | |
# Note: We have to use the solution files to get the right output paths, due to the mix of .NET 7 and .NET Standard projects. | |
- name: Publish outputs | |
run: | | |
dotnet publish --configuration Debug --output published/debug CoseSignTool/CoseSignTool.sln | |
dotnet publish --configuration Release --output published/release CoseSignTool/CoseSignTool.sln | |
# dotnet publish --no-build --configuration Debug --output published/debug CoseSignTool/CoseSignTool.sln # Once I have this working, move the debug publish and zip steps into the Build job so I don't have to build twice. | |
# Create zip files for release builds. Skip this step for continuous integration builds. | |
- name: Create zip files for the release | |
run: | | |
${{ matrix.zip_command_debug }} | |
${{ matrix.zip_command_release }} | |
working-directory: ./published | |
# List the contents of the published directory to make sure all the artifacts are there. | |
- name: List published directory | |
run: ${{ matrix.dir_command }} | |
working-directory: ./published | |
# Upload the zipped assets to the release. | |
- name: Upload artifacts | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ./published/CoseSignTool-*.zip | |
file_glob: true | |
overwrite: true | |