Skip to content

Deploy

Deploy #71

Workflow file for this run

# This workflow manages the deployement of BRIDGES:
# - NuGet Package for relevant branches (see "deploy-package" environment)
# - Pre-Release and Release for release and master branches, respectively
name: Deploy
on: # Controls the event triggering the workflow
workflow_dispatch: # The workflow can be triggered manually.
env: # Environment variable shared among the jobs
PKG_OUTPUT_DIR: ${{ github.workspace }}/output # Output directory for the NuGet Package
jobs:
manage_version:
runs-on: ubuntu-latest # Specify the runner os
environment: versioning # Specify the protection rules, variables and secrets
outputs:
pkg_version: ${{ steps.create-version.outputs.PKG_VERSION }}
pkg_release_type: ${{ steps.create-version.outputs.PKG_RELEASE_TYPE }}
steps:
# Get the repository variable and Increment the version
- name: Select and Increment version
id: create-version
shell: bash
run: |
version=${{vars.VERSION}} # Get the current package version
numbers=( ${version//./ } ) # Split into array to get version numbers
if [[ ${{github.ref}} =~ .*master$ ]]; then # For master branch
((numbers[0]++)) # Increment the major version number
version="${numbers[0]}.0.0"
echo "PKG_VERSION=$version" >> $GITHUB_OUTPUT
echo "PKG_RELEASE_TYPE=" >> $GITHUB_OUTPUT
elif [[ ${{github.ref}} =~ ^.*/release/.*$ ]]; then # For release branches
((numbers[1]++)) # Increment the minor version number
version="${numbers[0]}.${numbers[1]}.0"
echo "PKG_VERSION=$version" >> $GITHUB_OUTPUT
echo "PKG_RELEASE_TYPE=" >> $GITHUB_OUTPUT
elif [[ ${{github.ref}} =~ .*develop$ ]]; then # For release branch
((numbers[2]++)) # Increment the patch version number
version="${numbers[0]}.${numbers[1]}.${numbers[2]}"
echo "PKG_VERSION=$version" >> $GITHUB_OUTPUT
echo "PKG_RELEASE_TYPE=-alpha" >> $GITHUB_OUTPUT
else # For feature branches
((numbers[2]++)) # Increment the patch version number
version="${numbers[0]}.${numbers[1]}.${numbers[2]}"
echo "PKG_VERSION=$version" >> $GITHUB_OUTPUT
echo "PKG_RELEASE_TYPE=-beta" >> $GITHUB_OUTPUT
fi
# Generate a temporary token for the Github App
- name: Generate a GitHub App token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.VARIABLES_GITHUB_APP_ID }}
private-key: ${{ secrets.VARIABLES_GITHUB_APP_PRIVATE_KEY }}
# Update the repository variable
- name: Update version variable
env:
VAR_NAME: 'VERSION'
VAR_VALUE: ${{ steps.create-version.outputs.PKG_VERSION }}
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
gh api --method PATCH -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{github.repository}}/actions/variables/${{env.VAR_NAME}} -f name='${{env.VAR_NAME}}' -f value='${{env.VAR_VALUE}}'
nuget_packaging:
needs : manage_version # Specify jobs needed to run this one
runs-on : ubuntu-latest # Specify the runner os
steps:
# Check-out the branch
- name: Check-out Branch
uses: actions/checkout@v3
# Setup the .Net environment
- name: Setup .Net environmnent
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
# Build the solution
- name: Build Solution
run: dotnet build --configuration Release
# Runs the unit tests
- name : Test Project
run: dotnet test --verbosity normal
# Pack the project in a NuGet package
- name: Create NuGet
env:
PACKAGE_ID: 'BRIDGES'
run: |
dotnet pack ${{vars.PROJECT_PATH}} -p:PackageId=${{ env.PACKAGE_ID }} \
-p:PackageVersion=${{ needs.manage_version.outputs.PKG_VERSION }}${{ needs.manage_version.outputs.PKG_RELEASE_TYPE }} \
-p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg \
--output ${{ env.PKG_OUTPUT_DIR }}
# Upload the artefacts (Package and Symbols)
- name: Upload Github Artifacts
uses: actions/upload-artifact@v3
with:
name: package
path: ${{ env.PKG_OUTPUT_DIR }}/*
publish_nuget:
needs : nuget_packaging # Specify jobs needed to run this one
runs-on : ubuntu-latest # Specify the runner os
permissions: # Permissions for github.token (default is read)
packages: write
steps:
# Setup the .Net environment
- name: Setup .Net environmnent
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
# Download the artefacts (Package and Symbols)
- name: Download Github Artifacts
uses: actions/download-artifact@v3
with:
name: package
path: ${{ env.PKG_OUTPUT_DIR }}/
# Publish the NuGet package on GitHub
- name: Publish NuGet Package
run: |
dotnet nuget push ${{ env.PKG_OUTPUT_DIR }}/*.nupkg --api-key ${{ github.token }} --source ${{ vars.NUGET_SRC_URL }}
dotnet nuget push ${{ env.PKG_OUTPUT_DIR }}/*.snupkg --api-key ${{ github.token }} --source ${{ vars.NUGET_SRC_URL }}
create_tag:
needs: [manage_version, nuget_packaging] # Specify jobs needed to run this one
runs-on : ubuntu-latest # Specify the runner os
permissions: # Permissions for github.token (default is read)
contents: write
steps:
# Create reference (see https://docs.github.com/rest/git/refs#create-a-reference)
- name: Create version tag
env:
TAG_NAME: v${{ needs.manage_version.outputs.PKG_VERSION }}${{ needs.manage_version.outputs.PKG_RELEASE_TYPE }}
GH_TOKEN: ${{ github.token }}
run: |
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/git/refs -f ref='refs/heads/${{ env.TAG_NAME }}' -f sha=${{ github.sha }}
create_release:
needs : [manage_version, create_tag]
runs-on : ubuntu-latest
if : ${{ endsWith( github.ref , 'master') || contains( github.ref , '/release/') }}
steps:
# Download the artefacts (Package and Symbols)
- name: Download Github Artifacts
uses: actions/download-artifact@v3
with:
name: package
path: ${{ env.PKG_OUTPUT_DIR }}/
# Evaluate whether the Release should be a pre-release or not
- name: Evaluate if Pre-Release
shell: bash
run : |
if [[ ${{github.ref}} =~ .*master$ ]]; then
echo "IS_PRERELEASE=false" >> $GITHUB_ENV
else
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
fi
# Publish the Release
- name: Publish Release
uses: ncipollo/release-action@v1
with :
prerelease : ${{ env.IS_PRERELEASE }}
artifacts: ${{ env.PKG_OUTPUT_DIR }}/*
tag : v${{ needs.manage_version.outputs.PKG_VERSION }}${{ needs.manage_version.outputs.PKG_RELEASE_TYPE }}