Skip to content

Build & Release

Build & Release #78

Workflow file for this run

name: Build & Release
on:
workflow_dispatch:
inputs:
runUnitTest:
type: boolean
description: Run Unit Tests
default: true
runIntergrationTest:
type: boolean
description: Run Intergrations Tests
default: true
buildOptions:
required: false
type: choice
description: Build Options
default: Build
options:
- Build
releaseOption:
required: false
type: choice
description: Release Options
default: None
options:
- None
- PRE-RELEASE (release/** branches)
- RELEASE (main branch)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
WindowsSDKPath: 'C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools'
jobs:
manageVariable:
name: Manage Variables
runs-on: windows-latest
outputs:
releaseVersion: ${{ env.releaseVersion }}
packageVersion: ${{ env.packageVersion }}
publishPackages: ${{ env.publishPackages }}
release_sha: ${{ env.release_sha }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Apply versioning
if: success()
uses: ./.github/actions/env
- name: Package information
run: |
Write-Host "Release version: ${{ env.releaseVersion }}"
Write-Host "Package version: ${{ env.packageVersion }}"
Write-Host "Publish package: ${{ env.publishPackages }}"
Write-Host "Build Suffix: ${{ env.buildSuffix }}"
Write-Host "DNX_BUILD_VERSION: ${{ env.DNX_BUILD_VERSION }}"
Write-output "::notice title=Build branch::${{ github.ref_name }}"
Write-output "::notice title=Release version::${{ env.releaseVersion }}"
Write-output "::notice title=Packages version::${{ env.packageVersion }}"
Write-output "::notice title=Publish packages::${{ env.publishPackages }}"
build:
name: Build
needs: [manageVariable]
runs-on: windows-latest
env:
releaseVersion: ${{ needs.manageVariable.outputs.releaseVersion }}
packageVersion: ${{ needs.manageVariable.outputs.packageVersion }}
publishPackages: ${{ needs.manageVariable.outputs.publishPackages }}
release_sha: ${{ needs.manageVariable.outputs.release_sha }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Build
if: success()
run: msbuild\build.ps1 -configuration "Release" -skiptests "true" -verbosity "normal"
- name: Packages
if: success() && env.publishPackages == 'true'
run: msbuild\packGH.ps1 -version ${{ env.packageVersion }} -configuration "Release"
- name: Create Zip file
if: success() && env.publishPackages == 'true'
run: msbuild\createZipFile.ps1 -findVersion ${{ env.packageVersion }}
- name: Upload packages to artifacts
if: success() && env.publishPackages == 'true'
uses: actions/upload-artifact@v3
with:
name: Optimizely.Graph.Client-${{ env.packageVersion }}
path: ${{ github.workspace}}/artifacts/
# retention-days: 90
unit_test:
needs: [manageVariable, build]
name: Unit test
if: ${{ github.event.inputs.runUnitTest == 'true' }}
uses: ./.github/workflows/unitTest.yml
intergration_test:
needs: [manageVariable, build]
name: Intergrations test
if: ${{ github.event.inputs.runIntergrationTest == 'true' }}
uses: ./.github/workflows/intergrationTest.yml
secrets:
GATEWAYADDRESS: ${{ secrets.GATEWAYADDRESS }}
APPKEY: ${{ secrets.APPKEY }}
SECRET: ${{ secrets.SECRET }}
SINGLEKEY: ${{ secrets.SINGLEKEY }}
creatPreRelease:
name: Create Pre-Release
needs: [manageVariable, build, unit_test, intergration_test]
if: startsWith(github.ref, 'refs/heads/release') == true && github.event.inputs.releaseOption == 'PRE-RELEASE (release/** branches)'
runs-on: windows-latest
env:
releaseVersion: ${{ needs.manageVariable.outputs.releaseVersion }}
packageVersion: ${{ needs.manageVariable.outputs.packageVersion }}
publishPackages: ${{ needs.manageVariable.outputs.publishPackages }}
release_sha: ${{ needs.manageVariable.outputs.release_sha }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Fetch all tags
run: |
git fetch --prune --unshallow
git fetch --tags
- name: Prepare release notes
shell: powershell
run: |
Write-Output "Prepare release note"
msbuild\github\GetReleaseNotes.ps1 | Set-Content -Path "msbuild\github\ReleaseNotes.txt" -Force
- name: Create Github Release
id: create_github_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.releaseVersion }}
release_name: ${{ env.releaseVersion }}
commitish: ${{ env.release_sha }}
body_path: "msbuild/github/ReleaseNotes.txt"
draft: false
prerelease: true
- name: Create artifacts folder
run: |
if (Test-Path -Path "artifacts") {
Remove-Item -LiteralPath "artifacts" -Force -Recurse
}
New-Item -Path "artifacts" -ItemType Directory
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: Optimizely.Graph.Client-${{ env.packageVersion }}
path: artifacts
- name: Archive artifacts Release
uses: thedoctor0/zip-release@master
with:
type: 'zip'
filename: 'Optimizely.Graph.Client-${{ env.packageVersion }}.zip'
path: ./artifacts/*
- 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_github_release.outputs.upload_url }}
asset_path: ./Optimizely.Graph.Client-${{ env.packageVersion }}.zip
asset_name: Optimizely.Graph.Client-${{ env.packageVersion }}.zip
asset_content_type: application/zip
creatGitHubRelease:
name: Publish GitHub Release
needs: [manageVariable, build, unit_test, intergration_test]
if: github.ref == 'refs/heads/main' && github.event.inputs.releaseOption == 'RELEASE (main branch)'
runs-on: windows-latest
env:
releaseVersion: ${{ needs.manageVariable.outputs.releaseVersion }}
packageVersion: ${{ needs.manageVariable.outputs.packageVersion }}
publishPackages: ${{ needs.manageVariable.outputs.publishPackages }}
release_sha: ${{ needs.manageVariable.outputs.release_sha }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Check tag exist
uses: mukunku/[email protected]
id: checkTag
with:
tag: ${{env.releaseVersion}}
- name: Delete Pre-Release if exist
if: ${{ steps.checkTag.outputs.exists }} == "true"
uses: dev-drprasad/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.releaseVersion}}
delete_release: true
- name: Fetch all tags
run: |
git fetch --prune --unshallow
git fetch --tags
- name: Prepare release notes
shell: powershell
run: |
Write-Output "Prepare release note"
msbuild\github\GetReleaseNotes.ps1 | Set-Content -Path "msbuild\github\ReleaseNotes.txt" -Force
- name: Create Github Release
id: create_github_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.releaseVersion }}
release_name: ${{ env.releaseVersion }}
commitish: ${{ env.release_sha }}
body_path: "msbuild/github/ReleaseNotes.txt"
draft: false
prerelease: false
- name: Create artifacts folder
run: |
if (Test-Path -Path "artifacts") {
Remove-Item -LiteralPath "artifacts" -Force -Recurse
}
New-Item -Path "artifacts" -ItemType Directory
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: Optimizely.Graph.Client-${{ env.packageVersion }}
path: artifacts
- name: Archive artifacts Release
uses: thedoctor0/zip-release@master
with:
type: 'zip'
filename: 'Optimizely.Graph.Client-${{ env.packageVersion }}.zip'
path: ./artifacts/*
- 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_github_release.outputs.upload_url }}
asset_path: ./Optimizely.Graph.Client-${{ env.packageVersion }}.zip
asset_name: Optimizely.Graph.Client-${{ env.packageVersion }}.zip
asset_content_type: application/zip