Publish #8
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
# This workflow will publish the project | |
name: Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
config-file: | |
type: string | |
default: "./publish/config.json" | |
target-os: | |
type: choice | |
default: all | |
options: | |
- windows | |
- linux | |
- macos | |
- all | |
target-runtime: | |
type: choice | |
default: all | |
options: | |
- x86 | |
- x64 | |
- arm | |
- arm64 | |
- all | |
release: | |
types: [published] | |
env: | |
dotnet-version: 8.x | |
default-config-file: "./publish/config.json" | |
default-target-os: all | |
default-target-runtime: all | |
jobs: | |
prepare: | |
name: Prepare | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.publish-config-parser.outputs.profiles }} | |
status: ${{ steps.checker.outputs.status }} | |
project-file: ${{ steps.publish-config-parser.outputs.project-file }} | |
output-name: ${{ steps.publish-config-parser.outputs.output-name }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
- id: inputs | |
shell: bash | |
run: | | |
config_file='${{ github.event.inputs.config-file }}' | |
target_os='${{ github.event.inputs.target-os }}' | |
target_runtime='${{ github.event.inputs.target-runtime }}' | |
echo "config-file=${config_file:=${{ env.default-config-file }}}" >> $GITHUB_OUTPUT | |
echo "target-os=${target_os:=${{ env.default-target-os }}}" >> $GITHUB_OUTPUT | |
echo "target-runtime=${target_runtime:=${{ env.default-target-runtime }}}" >> $GITHUB_OUTPUT | |
- name: Parse configuration "${{ github.event.inputs.config-file }}" | |
id: publish-config-parser | |
uses: ./.github/actions/publish-config-parser | |
with: | |
config-file: ${{ env.config-file }} | |
tags: "${{ env.target-os }},${{ env.target-runtime }}" | |
env: | |
config-file: ${{ steps.inputs.outputs.config-file }} | |
target-os: ${{ steps.inputs.outputs.target-os }} | |
target-runtime: ${{ steps.inputs.outputs.target-runtime }} | |
- name: Check profiles | |
id: checker | |
run: | | |
profiles='${{ steps.publish-config-parser.outputs.profiles }}' | |
length=$( echo $profiles | jq '.include | length' ) | |
if(( $length > 0 )); then | |
echo "status=success" >> $GITHUB_OUTPUT | |
else | |
echo "status=failure" >> $GITHUB_OUTPUT | |
echo "No suitable publish profile found" | |
fi | |
publish: | |
name: Publish | |
needs: prepare | |
if: needs.prepare.outputs.status == 'success' | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: ${{fromJson(needs.prepare.outputs.matrix)}} | |
env: | |
output-name: ${{ needs.prepare.outputs.output-name }} | |
project-file: ${{ needs.prepare.outputs.project-file }} | |
configuration: ${{ matrix.configuration }} | |
framework: ${{ matrix.framework }} | |
runtime: ${{ matrix.runtime }} | |
publish-options: ${{ matrix.options }} | |
output-path: 'publish/output/${{ matrix.configuration }}/${{ matrix.framework }}/${{ matrix.runtime }}' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
- name: Install .NET | |
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0 | |
with: | |
dotnet-version: ${{ env.dotnet-version }} | |
- id: version-number | |
uses: finebits/github-actions/version-number@v1 | |
- uses: finebits/github-actions/pre-build/replace@v1 | |
with: | |
file: ./src/Eppie.CLI/Eppie.CLI/Options/AuthorizationOptions.cs | |
placeholder: '\"<Gmail-ClientId>\"' | |
value: "${{ secrets.GMAIL_CLIENT_ID }}" | |
- uses: finebits/github-actions/pre-build/replace@v1 | |
with: | |
file: ./src/Eppie.CLI/Eppie.CLI/Options/AuthorizationOptions.cs | |
placeholder: '\"<Gmail-ClientSecret>\"' | |
value: "${{ secrets.GMAIL_CLIENT_SECRET }}" | |
- uses: finebits/github-actions/pre-build/replace@v1 | |
with: | |
file: ./src/Eppie.CLI/Eppie.CLI/Options/AuthorizationOptions.cs | |
placeholder: '\"<Outlook-ClientId>\"' | |
value: "${{ secrets.OUTLOOK_CLIENT_ID }}" | |
- name: Publish ${{ env.output-name }} [${{ env.version-short }}] | |
run: | | |
dotnet publish "${{ env.project-file }}" --output "${{ env.output-path }}" --configuration "${{ env.configuration }}" --framework "${{ env.framework }}" --runtime "${{ env.runtime }}" --property:Version="${{ env.version-full }}" ${{ env.publish-options }} | |
env: | |
version-full: "${{ steps.version-number.outputs.suffix-githash-version }}" | |
version-short: "${{ steps.version-number.outputs.suffix-version }}" | |
- name: Sign files with Trusted Signing | |
if: matrix.os == 'windows-latest' | |
uses: azure/trusted-signing-action@e6530f2780a4ab2153b0cea1f87cd8d0a3a4d07a # v0.3.19 | |
with: | |
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }} | |
endpoint: https://neu.codesigning.azure.net/ | |
trusted-signing-account-name: ${{ secrets.TRUSTED_SIGNING_ACCOUNT_NAME }} | |
certificate-profile-name: ${{ secrets.CERTIFICATE_PROFILE_NAME }} | |
files-folder: ${{ env.output-path }} | |
files-folder-filter: exe | |
file-digest: SHA256 | |
timestamp-rfc3161: http://timestamp.acs.microsoft.com | |
timestamp-digest: SHA256 | |
- name: Upload artifacts | |
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | |
with: | |
name: "${{ env.output-name }}-${{ env.runtime }} [${{ env.version-short }}]" | |
path: "${{ env.output-path }}" | |
env: | |
artifact-name: "${{ env.output-name }}" | |
version-short: "${{ steps.version-number.outputs.suffix-version }}" | |
upload-assets: | |
name: Upload Assets | |
if: github.event_name == 'release' | |
needs: publish | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
env: | |
artifacts-root: artifacts | |
assets-root: assets | |
steps: | |
- name: Download All Artifacts | |
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 | |
with: | |
path: "${{ env.artifacts-root }}" | |
- name: Prepare Assets | |
shell: bash | |
run: | | |
asset_root="${{ env.assets-root }}" | |
mkdir -p "${asset_root}" | |
artifact_pattern="${{ env.artifacts-root }}/*" | |
for item in $artifact_pattern ; do | |
if [ -d "$item" ] ; then | |
item_name="${item##*/}" | |
# remove version | |
asset_name="${item_name% [*}" | |
if [[ "$asset_name" == *"-osx-"* || "$asset_name" == *"-linux-"* ]]; then | |
tar -czf "$asset_root/${asset_name}.tar.gz" -C "$item" . && echo "Archiving of the asset '$asset_name' has been completed successfully." || echo "::warning::Failed to archive asset '$asset_name'" | |
else | |
zip -rjq "$asset_root/${asset_name}.zip" "$item" && echo "Archiving of the asset '$asset_name' has been completed successfully." || echo "::warning::Failed to archive asset '$asset_name'" | |
fi | |
fi | |
done | |
- name: Upload All Assets | |
uses: finebits/github-actions/upload-release-asset@v1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.release.tag_name }} | |
path: "${{ env.assets-root }}/*" |