Skip to content
name: Build and Release .NET Framework App
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Visual Studio
uses: microsoft/setup-msbuild@v2
with:
vs-version: 'latest'
msbuild-architecture: 'x64'
- name: Install NuGet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x' # Adjust this version if needed
- name: Restore NuGet packages
run: nuget restore SubtitleEdit.sln
- name: Compile UpdateAssemblyInfo
run: msbuild src/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj /p:Configuration=Debug /p:OutputPath=bin/debug
- name: Verify Compile UpdateAssemblyInfo
run: |
if not exist "src/UpdateAssemblyInfo/bin/Debug/UpdateAssemblyInfo.exe" (
echo UpdateAssemblyInfo.exe not found!
exit 1
)
echo UpdateAssemblyInfo.exe compiled successfully!
shell: cmd
- name: Generate timestamp
id: generate_timestamp
shell: pwsh
run: |
# Generate timestamp in the format YYYYMMDD-HHMMSS
$timestamp = (Get-Date).ToString("yyyyMMdd-HHmmss")
Write-Output "TIMESTAMP=$timestamp" >> $env:GITHUB_ENV
- name: Set version number (e.g., from a file or env)
id: set_version
shell: pwsh
run: |
# Manually or automatically set a semantic version number
$version = "1.0.0" # You can increment this number based on your strategy
Write-Output "VERSION=$version" >> $env:GITHUB_ENV
- name: Delete existing tag if it exists
run: |
git tag -d $env:VERSION || true
git push --delete origin $env:VERSION || true
- name: Create a new semantic version tag
shell: pwsh
run: |
$version = $env:VERSION
git tag "$version"
git push origin "$version"
- name: Run build.bat
run: |
.\build.bat Build
shell: cmd
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: release-${{ env.TIMESTAMP }}
release_name: Release ${{ env.TIMESTAMP }}
body: Release generated by GitHub Actions with timestamp ${{ env.TIMESTAMP }}.
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Debug upload_url
run: echo Upload URL is ${{ steps.create_release.outputs.upload_url }}
shell: cmd
- name: Search for SubtitleEdit-*.zip
id: find_zip
run: |
for /r %%i in (SubtitleEdit-*.zip) do @echo ::set-output name=zip_path::%%i
shell: cmd
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.find_zip.outputs.zip_path }}
asset_name: SubtitleEdit-Release.zip
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}