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

Add workflow for manually created releases #27

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/ManuaRelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Manual Release
on:
release:
types: [published]

jobs:
get_release_type:
runs-on: ubuntu-latest
outputs:
release_type: ${{ steps.get_release_type.outputs.release_type }}
steps:
- uses: actions/checkout@v2
- name: Get Release Type
id: get_release_type
run: |
if [[ ${{ github.event.release.prerelease }} == true ]]; then
echo "This is an automated release. Skipping..."
echo "::set-output name=is_official_release::false"
else
echo "This is an official release. Uploading assets..."
echo "::set-output name=is_official_release::true"
fi

# Upload the release artifacts but only if it's an official release
- name: Call Upload Assets action
if: steps.get_release_type.outputs.is_official_release
uses: ./.github/workflows/UploadAssets.yml
58 changes: 58 additions & 0 deletions .github/workflows/UploadAssets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Upload Assets
on:
workflow_call:

jobs:
# Publish and zip the binaries and upload them to the release.
release_assets:
name: release-assets
if: ${{ github.event_name != 'pull_request' }}
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:
# Checkout the branch.
- name: Checkout code again
uses: actions/checkout@v3

# Build and publish the binaries to ./published.
# 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

# Create zip files for release.
- 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
115 changes: 29 additions & 86 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ name: Build, Test, and Publish
on:
push:
branches: [ "main" ] # Trigger on pushes to the main branch.
tags:
- '!*pre*' # Trigger on the creation of non-prerelease tags.
pull_request:
branches: [ "*" ] # Trigger on all branches for pull requests.

Expand Down Expand Up @@ -86,7 +84,7 @@ jobs:
with:
dotnet-version: 7.0.x

# Use the Dotnet Test command to load dependencies, build, and test the code.
# Load the dependencies, build, and test the code.
- name: Build and Test debug
run: dotnet test --verbosity normal CoseSignTool/CoseSignTool.sln

Expand All @@ -98,7 +96,6 @@ jobs:

# Create a semantically versioned release.
# A prerelease is created for every push to the main branch.
# An official release is created when a tag is created manually on GitHub.
create_release:
name: Create Release
if: ${{ github.event_name == 'push' }}
Expand All @@ -108,16 +105,16 @@ jobs:
steps:
- name: Checkout code # TODO: See if I can configure this step, or v3, to replace the Fetch and checkout step below.
uses: actions/checkout@v3
with:
ref: main
# with:
# ref: main

# # Checkout the main branch so we can see the correct tag set.
# - name: Fetch and checkout main
# run: |
# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action"
# git fetch
# git checkout main
# Checkout the main branch so we can see the correct tag set.
- name: Fetch and checkout main
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git fetch
git checkout main

# Create a semantically versioned tag that increments the last release.
- name: Create SemVer tag
Expand All @@ -127,19 +124,19 @@ jobs:
main_branch_name: "main"
debug: true

# Set the tag name and release type, based on whether the workflow was triggered by a tag or by a push to Main.
- name: Choose tag and release type
id: choose-tag
run: |
if [[ ${{ github.ref }} == refs/tags/* ]]; then
echo "This is an official release. Setting tag to ${{ github.ref }}."
echo "::set-output name=TAG_NAME::${{ github.ref }}"
echo "::set-output name=is_prerelease::false"
else
echo "This is an automated release. Setting tag to ${{ steps.semver-tag.outputs.semver_tag }}."
echo "::set-output name=TAG_NAME::${{ steps.semver-tag.outputs.semver_tag }}"
echo "::set-output name=is_prerelease::true"
fi
# # Set the tag name and release type, based on whether the workflow was triggered by a tag or by a push to Main.
# - name: Choose tag and release type
# id: choose-tag
# run: |
# if [[ ${{ github.ref }} == refs/tags/* ]]; then
# echo "This is an official release. Setting tag to ${{ github.ref }}."
# echo "::set-output name=TAG_NAME::${{ github.ref }}"
# echo "::set-output name=is_prerelease::false"
# else
# echo "This is an automated release. Setting tag to ${{ steps.semver-tag.outputs.semver_tag }}."
# echo "::set-output name=TAG_NAME::${{ steps.semver-tag.outputs.semver_tag }}"
# echo "::set-output name=is_prerelease::true"
# fi

# Create the release.
- name: Create Release
Expand All @@ -149,69 +146,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Get the tag name and release name from the previous step.
tag_name: ${{ steps.choose-tag.outputs.TAG_NAME }}
release_name: Release ${{ steps.choose-tag.outputs.TAG_NAME }}
tag_name: ${{ steps.semver-tag.outputs.semver_tag }}
release_name: Release ${{ steps.semver-tag.outputs.semver_tag }}

# Generate release text from changelog.
body_path: ./CHANGELOG.md

# Always use prerelease for automated releases. Official releases are created manually.
prerelease: ${{ steps.choose-tag.outputs.is_prerelease }}


# Publish and zip the binaries and upload them to the release.
release_assets:
name: release-assets
needs: [ build, create_release ]
if: ${{ github.event_name != 'pull_request' }}
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:
# Checkout the branch.
- name: Checkout code again
uses: actions/checkout@v3

# Build and publish the binaries to ./published.
# 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
prerelease: true

# TODO: See if I can get these to run with --no-build.

# Create zip files for release.
- 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
# Upload the release artifacts.
- name: Call Upload Assets action
uses: ./.github/workflows/UploadAssets.yml