Last active
November 18, 2019 00:56
-
-
Save nogic1008/0be6a52a74b28b9909549f4d48a1cbd9 to your computer and use it in GitHub Desktop.
Github Actions .NET Core Sample
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: .NET Core | |
on: [push, pull_request] | |
jobs: | |
test: | |
name: Debug Build & Test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
# Use lts, maintenance, current, and preview version. | |
# Learn more, see https://github.com/dotnet/core/blob/master/release-notes/releases-index.json | |
dotnet-version: ['2.1.802', '2.2.402', '3.0.100', '3.1.100-preview3-014645'] | |
env: | |
DOTNET_CLI_TELEMETRY_OPTOUT: 1 | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
NUGET_XMLDOC_MODE: skip | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Setup .NET Core ${{ matrix.dotnet-version }} | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Build | |
run: dotnet build -c Debug | |
- name: Test | |
run: dotnet test -c Debug --no-build | |
release: | |
name: Create Github Release | |
if: contains(github.ref, 'tags/v') # works only version tagged | |
needs: [test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1.0.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: false | |
prerelease: false | |
- name: Output Release URL File | |
run: echo ${{ steps.create_release.outputs.upload_url }} > release_url.txt | |
- name: Save Release URL File for publish | |
uses: actions/upload-artifact@v1 | |
with: | |
name: release_url | |
path: release_url.txt | |
publish: | |
if: contains(github.ref, 'tags/v') # works only version tagged | |
needs: [test, release] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
rid: [win-x64, linux-x64, osx-x64] | |
env: | |
DOTNET_CLI_TELEMETRY_OPTOUT: 1 | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
NUGET_XMLDOC_MODE: skip | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Load Release URL File from release job | |
uses: actions/download-artifact@v1 | |
with: | |
name: release_url | |
- name: Setup .NET Core 3.0 (current) | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 3.0.100 | |
- name: Build | |
run: | | |
dotnet publish -c Release --self-contained -r ${{ matrix.rid }} -o ./bin/${{ matrix.rid }} | |
zip -r ${{ matrix.rid }} ./bin/${{ matrix.rid }} | |
- name: Get Release File Name & Upload URL | |
id: get_release_info | |
run: | | |
echo ::set-output name=file_name::${REPOSITORY_NAME##*/}-${TAG_REF_NAME##*/v} #ex. RepositoryName-1.0.0 | |
value=`cat release_url.txt` | |
echo ::set-output name=upload_url::$value | |
env: | |
TAG_REF_NAME: ${{ github.ref }} | |
REPOSITORY_NAME: ${{ github.repository }} | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.get_release_info.outputs.upload_url }} | |
asset_path: ./${{ matrix.rid }}.zip | |
asset_name: ${{ steps.get_release_info.outputs.file_name }}-${{ matrix.rid }}.zip | |
asset_content_type: application/zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment