From cf355ad696699b6b4ea4fbd81a09e8e41dc510ff Mon Sep 17 00:00:00 2001 From: Yury Glushkov Date: Thu, 9 Apr 2020 20:04:46 +0300 Subject: [PATCH] Release workflow added. --- .github/workflows/build-and-test.yml | 23 ---- .github/workflows/release.yml | 104 ++++++++++++++++++ .../{coverage-report.yml => test.yml} | 5 +- README.md | 2 +- 4 files changed, 109 insertions(+), 25 deletions(-) delete mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/release.yml rename .github/workflows/{coverage-report.yml => test.yml} (89%) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index a8cf5d3..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: build and test - -on: - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.2.207 - - name: Install dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test - run: dotnet test --no-restore --verbosity normal diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..725c6b0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +name: release + +on: + release: + types: + - published + +env: + RELEASE_CLIENT: true + RELEASE_CONTRACT: true + RELEASE_JOB: false + RELEASE_SERVICE: true + + CLIENT_PROJECT: ./client/MAVN.Service.NotificationSystemBroker.Client/MAVN.Service.NotificationSystemBroker.Client.csproj + CONTRACT_PROJECT: ./contract/MAVN.Service.NotificationSystemBroker.Contract/MAVN.Service.NotificationSystemBroker.Contract.csproj + JOB_DOCKER_IMAGE: + JOB_PROJECT: + SERVICE_DOCKER_IMAGE: notification-system-broker-service + SERVICE_PROJECT: ./src/MAVN.Service.NotificationSystemBroker/MAVN.Service.NotificationSystemBroker.csproj + + + +jobs: + publish-release: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + # Set release version + - name: Get release version from tag + id: version + uses: LykkeBusiness/get-semver-from-tag-action@v1.0.2 + with: + tag: ${{ github.ref }} + - name: Set version for release + uses: allenevans/set-env@v1.0.0 + with: + VERSION: ${{ steps.version.outputs.non-prefixed }} + + # Login to Docker Hub + - name: Login to docker hub + if: env.RELEASE_JOB == 'true' || env.RELEASE_SERVICE == 'true' + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD + + # Build solution + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 2.2.207 + - name: Install dependencies + run: dotnet restore + - name: Build solution + run: dotnet build --configuration Release --no-restore /p:Version=$VERSION + + # Build Docker images + - name: Build docker image for a job + if: env.RELEASE_JOB == 'true' + run: | + dotnet publish $JOB_PROJECT --configuration Release --output ../../docker/job --no-build /p:Version=$VERSION + docker build --tag openmavn/$JOB_DOCKER_IMAGE:$VERSION ./docker/job + - name: Build docker image for a service + if: env.RELEASE_SERVICE == 'true' + run: | + dotnet publish $SERVICE_PROJECT --configuration Release --output ../../docker/service --no-build /p:Version=$VERSION + docker build --tag openmavn/$SERVICE_DOCKER_IMAGE:$VERSION ./docker/service + + # Pack NuGet packages + - name: Pack client NuGet package + if: env.RELEASE_CLIENT == 'true' + run: dotnet pack $CLIENT_PROJECT --configuration Release --output ../../packages --no-build --include-symbols --include-source /p:SymbolPackageFormat=snupkg /p:Version=$VERSION + - name: Pack contract NuGet package + if: env.RELEASE_CONTRACT == 'true' + run: dotnet pack $CONTRACT_PROJECT --configuration Release --output ../../packages --no-build --include-symbols --include-source /p:SymbolPackageFormat=snupkg /p:Version=$VERSION + + # Push Docker Images + - name: Push job docker image + if: env.RELEASE_JOB == 'true' + run: docker push openmavn/$JOB_DOCKER_IMAGE:$VERSION + - name: Push service docker image + if: env.RELEASE_SERVICE == 'true' + run: docker push openmavn/$SERVICE_DOCKER_IMAGE:$VERSION + + # Push NuGet packages + - name: Push NuGet packages + if: env.RELEASE_CLIENT == 'true' || env.RELEASE_CONTRACT == 'true' + env: + API_KEY: ${{ secrets.NUGET_ORG_API_KEY }} + run: dotnet nuget push ./packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key $API_KEY + + # Create next release draft + - name: Create next release draft + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: next + release_name: next + body: + draft: true diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/test.yml similarity index 89% rename from .github/workflows/coverage-report.yml rename to .github/workflows/test.yml index 14b35b0..b6f71ec 100644 --- a/.github/workflows/coverage-report.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,8 @@ -name: calculate coverage +name: test on: + pull_request: + branches: [ master ] push: branches: [ master ] @@ -22,6 +24,7 @@ jobs: - name: Test run: dotnet test --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov - name: Publish coverage report + if: github.event_name == 'push' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index f21b4ff..3cca779 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # MAVN.Service.NotificationSystemBroker -![calculate coverage](https://github.com/OpenMAVN/MAVN.Service.NotificationSystemBroker/workflows/calculate%20coverage/badge.svg) +![test](https://github.com/OpenMAVN/MAVN.Service.NotificationSystemBroker/workflows/test/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/OpenMAVN/MAVN.Service.NotificationSystemBroker/badge.svg?branch=master)](https://coveralls.io/github/OpenMAVN/MAVN.Service.NotificationSystemBroker?branch=master)