diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8f30cfb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,108 @@ +name: Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: windows-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get base version from version.json + id: version + uses: notiz-dev/github-action-json-property@release + with: + path: version.json + prop_path: 'version' + + - name: Set branch name (push) + if: startsWith(github.ref, 'refs/heads/') + shell: pwsh + run: | + $branch = "${{ github.ref }}" -replace 'refs/heads/', '' -replace '[\s_]', '-' + echo "BRANCH_NAME=$branch" >> $env:GITHUB_ENV + + - name: Set branch name (PR) + if: startsWith(github.ref, 'refs/pull/') + shell: pwsh + run: | + $prNumber = "${{ github.ref }}" -replace 'refs/pull/', '' -replace '/merge', '' + echo "BRANCH_NAME=PR-$prNumber" >> $env:GITHUB_ENV + + - name: Set package version (master) + if: github.ref == 'refs/heads/master' + shell: pwsh + run: | + $numericVersion = "${{ steps.version.outputs.prop }}.${{ github.run_number }}" + echo "PACKAGE_VERSION=$numericVersion" >> $env:GITHUB_ENV + echo "ASSEMBLY_VERSION=$numericVersion.0" >> $env:GITHUB_ENV + + - name: Set package version (non-master) + if: github.ref != 'refs/heads/master' + shell: pwsh + run: | + $sha = "${{ github.sha }}".Substring(0, 8) + $numericVersion = "${{ steps.version.outputs.prop }}.${{ github.run_number }}" + echo "PACKAGE_VERSION=$numericVersion-$env:BRANCH_NAME-$sha" >> $env:GITHUB_ENV + echo "ASSEMBLY_VERSION=$numericVersion.0" >> $env:GITHUB_ENV + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Restore dependencies + run: dotnet restore Seq.Client.WindowsLogins.sln + + - name: Build + run: dotnet build Seq.Client.WindowsLogins.sln --configuration Release --no-restore /p:Version="$env:PACKAGE_VERSION" /p:AssemblyVersion="$env:ASSEMBLY_VERSION" /p:FileVersion="$env:ASSEMBLY_VERSION" + + - name: Test + run: dotnet test Seq.Client.WindowsLogins.sln --configuration Release --no-build --verbosity normal + + - name: Create release package + id: create_package + shell: pwsh + run: | + $outputDir = "Seq.Client.WindowsLogins/bin/Release/net462" + $zipName = "Seq.Client.WindowsLogins-$env:PACKAGE_VERSION.zip" + Compress-Archive -Path "$outputDir/*" -DestinationPath $zipName + echo "ZIP_NAME=$zipName" >> $env:GITHUB_ENV + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: Seq.Client.WindowsLogins-${{ env.PACKAGE_VERSION }} + path: Seq.Client.WindowsLogins/bin/Release/net462/ + + - name: Comment on PR with artifact link + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const version = process.env.PACKAGE_VERSION || 'unknown'; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `📦 **Build artifact ready:** \`Seq.Client.WindowsLogins-${version}\`\n\nDownload it from the [workflow run artifacts](${runUrl}#artifacts).` + }); + + - name: Create GitHub release + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: softprops/action-gh-release@v2 + with: + tag_name: v${{ env.PACKAGE_VERSION }} + name: Release v${{ env.PACKAGE_VERSION }} + files: ${{ env.ZIP_NAME }} + generate_release_notes: true diff --git a/version.json b/version.json new file mode 100644 index 0000000..dde0723 --- /dev/null +++ b/version.json @@ -0,0 +1,3 @@ +{ + "version": "1.1" +}