name: Build and Release on: push: tags: - '*' jobs: build: if: github.ref == 'refs/heads/master' runs-on: windows-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: "8.x" - name: Restore dependencies run: dotnet restore NebulaAuth.sln - name: Build run: dotnet build NebulaAuth.sln --configuration Release - name: Get version from assembly id: get-version shell: pwsh run: | $content = Get-Content -Path "NebulaAuth/NebulaAuth.csproj" -Raw $version = [regex]::Match($content, '(.*?)<\/AssemblyVersion>').Groups[1].Value Write-Output "VERSION=$version" >> $env:GITHUB_ENV - name: Check if tag exists id: tag_exists run: | if (git tag -l | Select-String -Pattern "^${env:VERSION}$") { Write-Output "Version $env:VERSION already exists." exit 1 } - name: Check changelog run: | if (-not (Test-Path "changelog/${env:VERSION}.html")) { Write-Output "Changelog file changelog/${env:VERSION}.html does not exist." exit 1 } - name: Insert date into changelog run: | $date = Get-Date -Format "dd.MM.yyyy" (Get-Content "changelog/${env:VERSION}.html") -replace '(?<=
).*?(?=
)', $date | Set-Content "changelog/${env:VERSION}.html" - name: Extract changelog description id: extract_description run: | $description = (Get-Content "changelog/${env:VERSION}.html" | Select-String -Pattern '(?<=
).*?(?=
)' | ForEach-Object { $_.Matches.Value }) -replace '', "`n" Write-Output "DESCRIPTION=$description" >> $env:GITHUB_ENV - name: Create ZIP run: | New-Item -ItemType Directory -Path release -Force Compress-Archive -Path NebulaAuth/bin/Release -DestinationPath release/NebulaAuth.${env:VERSION}.zip - name: Create GitHub Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ env.VERSION }} release_name: NebulaAuth ${{ env.VERSION }} body: | ${{ env.DESCRIPTION }} 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: release/NebulaAuth.${{ env.VERSION }}.zip asset_name: NebulaAuth.${{ env.VERSION }}.zip asset_content_type: application/zip - name: Update XML and Changelog html shell: pwsh run: | $xmlContent = @" ${env:VERSION}.0 https://github.com/${env:GITHUB_REPOSITORY}/releases/download/${env:VERSION}/NebulaAuth.${env:VERSION}.zip https://achiez.github.io/NebulaAuth-Steam-Desktop-Authenticator-by-Achies/changelog/${env:VERSION}.html false "@ $xmlContent | Out-File -FilePath update.xml -Encoding UTF8 -Force git config --global user.name 'github-actions' git config --global user.email 'github-actions@github.com' git add changelog/${env:VERSION}.html update.xml git commit -m "Update version to ${env:VERSION} and add changelog" git push origin master