This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
Build and Publish Release #1
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
name: Build and Publish Release | |
on: | |
workflow_dispatch: | |
jobs: | |
build_and_release: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Extract version and changelog | |
id: extract_info | |
run: | | |
$content = Get-Content -Path './CHANGELOG.md' -Raw | |
$matches = [Regex]::Matches($content, '--\s+(\d{4}\.\d{2}\.\d{2})\s+-\s+V([^\s]+)\r?\n\r?\n(-\s+[^-]+(?:\r?\n-.*?)*)(?=\r?\n--|\z)', 'Singleline') | |
$latest = $matches[0] | |
$version = $latest.Groups[2].Value | |
$changelog = $latest.Groups[3].Value.Trim() | |
echo "VERSION=$version" >> $GITHUB_ENV | |
echo "::set-output name=version::$version" | |
echo "::set-output name=changelog::$changelog" | |
- name: Get existing tags | |
id: get_tags | |
run: | | |
git fetch --tags | |
$tags = git tag | |
echo "::set-output name=tags::$tags" | |
- name: Set new tag | |
id: set_tag | |
run: | | |
$baseTag = "v${{ steps.extract_info.outputs.version }}" | |
$tags = "${{ steps.get_tags.outputs.tags }}" | |
$count = 0 | |
while ($tags -contains "$baseTag-$count") { | |
$count++ | |
} | |
if ($tags -contains $baseTag) { | |
$newTag = "$baseTag-$count" | |
} else { | |
$newTag = $baseTag | |
} | |
echo "New tag: $newTag" | |
echo "::set-output name=new_tag::$newTag" | |
echo "NewTag=$newTag" >> $GITHUB_ENV | |
- name: Build Project | |
run: dotnet build --configuration Release | |
- name: Publish Project | |
run: dotnet publish --configuration Release --output ./publish | |
- name: Zip Publish Folder | |
run: | | |
Compress-Archive -Path ./publish/* -DestinationPath ./publish/${{ github.repository }}.zip | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.set_tag.outputs.new_tag }} | |
release_name: ${{ github.repository }} ${{ steps.set_tag.outputs.new_tag }} | |
body: ${{ steps.extract_info.outputs.changelog }} | |
draft: false | |
prerelease: false | |
- 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: ./publish/${{ github.repository }}.zip | |
asset_name: ${{ github.repository }}-${{ steps.set_tag.outputs.new_tag }}.zip | |
asset_content_type: application/zip |