Skip to content

Build & Release

Build & Release #91

Workflow file for this run

# This workflow will build and release a .NET project
name: Build & Release
# Run the workflow after changes in the "master" branch
on:
push:
branches: [ "master" ]
workflow_dispatch:
jobs:
build_and_release:
# Use "windows-2019" runner for .NET Framework 4.x projects and "windows-latest" for .NET Core projects
runs-on: windows-2019
# Define env variables containing project properties
# Use TIMT (The-Infinite-Monkey-Theorem) prefix for variable names
env:
TIMT_PROJECT_NAME: 'Snaffler'
TIMT_SOLUTION_FILE: 'Snaffler\Snaffler.sln'
TIMT_BINARY_PATH: '${{ github.workspace }}\Snaffler\Snaffler\bin\Release'
TIMT_BINARY_FILE: '${{ github.workspace }}\Snaffler\Snaffler\bin\Release\Snaffler.exe'
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
with:
path: Snaffler
- name: Download SharpPack.zip
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'hasksomatotoian/SharpPack'
file: 'SharpPack.zip'
target: 'SharpPack\SharpPack.zip'
token: ${{ secrets.REPO_ACCESS_KEY }}
- name: Decompress SharpPack.zip
run: |
Expand-Archive -Path ".\SharpPack\SharpPack.zip" -DestinationPath ".\SharpPack\"
shell: powershell
- name: Obfuscate
run: SharpPack\SharpPack.exe $env:TIMT_SOLUTION_FILE -Rename -Anonymize
- name: Install NuGet
uses: NuGet/setup-nuget@v1.2.0
- name: Restore
run: nuget restore $env:TIMT_SOLUTION_FILE
- name: Install MSBuild
uses: microsoft/setup-msbuild@v1.1
- name: Build
run: msbuild $env:TIMT_SOLUTION_FILE -t:rebuild -property:Configuration=Release -property:DebugSymbols=false -property:DebugType=None
# Get release version as a combination of the project assembly version and the GitHub build number
- name: Get Release Version
id: get_release_version
run: |
$assembly = [System.Reflection.Assembly]::LoadFile("$env:TIMT_BINARY_FILE")
$version = $assembly.GetName().Version.ToString() + '-' + '${{ github.run_number }}'
echo "::set-output name=version::$version"
shell: powershell
# Create ZIP file containing project binaries
- name: Create Zip
id: create_zip
run: |
Compress-Archive -Path "$env:TIMT_BINARY_PATH\*" -DestinationPath ".\$env:TIMT_PROJECT_NAME.zip"
echo "::set-output name=assetFilename::$env:TIMT_PROJECT_NAME.zip"
shell: powershell
# Create new project release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_release_version.outputs.version }}
release_name: ${{ env.TIMT_PROJECT_NAME }} v${{ steps.get_release_version.outputs.version }}
draft: false
prerelease: false
# Attach ZIP file containing project binaries to the release
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.create_zip.outputs.assetFilename }}
asset_name: ${{ env.TIMT_PROJECT_NAME }}.zip
asset_content_type: application/zip