Update build-and-publish.yml (#457) #302
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 Release | |
on: | |
push: | |
branches: [ main, pre-release, release ] | |
paths-ignore: | |
- 'docs/**' | |
env: | |
DOTNET_VERSION: 7.0.x | |
jobs: | |
build: | |
runs-on: windows-latest | |
outputs: | |
version: ${{ steps.set-version-to-output.outputs.version }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
- uses: actions/setup-java@v2 | |
with: | |
distribution: 'zulu' | |
java-version: '11' | |
- name: Install MAUI | |
run: dotnet workload install maui | |
- name: Add msbuild to PATH | |
uses: microsoft/[email protected] | |
- name: Update version number | |
if: github.ref != 'refs/heads/release' | |
shell: pwsh | |
run: | | |
$doc = [XML](Get-Content 'Source\Directory.Build.props') | |
$doc.Project.PropertyGroup.Version += '-pre' + (Get-Date).ToString("yyyyMMddHHmm") | |
$doc.Save('Source\Directory.Build.props') | |
- name: Set version to outputs | |
id: set-version-to-output | |
shell: pwsh | |
run: | | |
$doc = [XML](Get-Content 'Source\Directory.Build.props') | |
echo "version=$($doc.Project.PropertyGroup.Version) >> $GITHUB_OUTPUT" | |
- name: Install dependencies | |
run: dotnet restore ReactiveProperty.sln | |
- name: Build | |
run: dotnet build ReactiveProperty.sln -c Release /p:ContinuousIntegrationBuild=True /p:EmbedUntrackedSources=True | |
- name: Test | |
run: dotnet test ReactiveProperty.sln --no-restore --verbosity normal | |
- name: Copy package files | |
run: | | |
mkdir dist | |
Copy-Item (Get-ChildItem -Path "Source/**/*.nupkg" -Recurse) -Destination dist | |
Copy-Item (Get-ChildItem -Path "Source/**/*.snupkg" -Recurse) -Destination dist | |
shell: pwsh | |
- name: Archive NuGet packages | |
uses: actions/upload-artifact@v1 | |
with: | |
name: dist | |
path: dist | |
release-to-nuget: | |
runs-on: windows-latest | |
needs: [build] | |
if: github.event_name == 'push' && (github.ref == 'refs/heads/pre-release' || github.ref == 'refs/heads/release') | |
steps: | |
- name: Download archives | |
uses: actions/download-artifact@v2 | |
with: | |
name: dist | |
- name: Publish packages | |
run: dotnet nuget push **/*.nupkg --skip-duplicate -k ${{ secrets.NUGET_APIKEY }} -s https://api.nuget.org/v3/index.json | |
create-release: | |
runs-on: windows-latest | |
needs: [build] | |
if: github.event_name == 'push' && (github.ref == 'refs/heads/pre-release' || github.ref == 'refs/heads/release') | |
steps: | |
- name: Download archives | |
uses: actions/download-artifact@v2 | |
with: | |
name: dist | |
path: dist | |
- uses: rickstaa/action-create-tag@v1 | |
id: "tag_create" | |
with: | |
tag: ${{ needs.build.outputs.version }} | |
tag_exists_error: true | |
message: ${{ needs.build.outputs.version }} | |
- name: Create a release | |
id: create_release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ needs.build.outputs.version }} | |
name: Release ${{ needs.build.outputs.version }} | |
body: | | |
TBD | |
draft: true | |
prerelease: ${{ github.ref == 'refs/heads/pre-release' }} | |
- name: Archive packages | |
shell: pwsh | |
run: | | |
Compress-Archive -Path dist -DestinationPath packages.zip | |
- name: Upload Release Asset | |
id: 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: packages.zip | |
asset_name: packages-${{ needs.build.outputs.version }}.zip | |
asset_content_type: application/zip |