CI/CD #23
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: CI/CD | |
on: | |
workflow_dispatch: | |
inputs: | |
release_major: | |
description: 'Release - major number' | |
required: true | |
default: '3' # major | |
release_minor: | |
description: 'Release - minor number' | |
required: true | |
default: '4' # minor | |
release_patch: | |
description: 'Release - patch number (previous 1)' | |
required: true | |
release_name: | |
description: 'Additional name of the release' | |
required: true | |
release_suffix: | |
description: 'Release - version suffix (including dash!)' | |
required: false | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
release_version: ${{github.event.inputs.release_major}}.${{github.event.inputs.release_minor}}.${{github.event.inputs.release_patch}}.${{github.run_number}} | |
bin_dir: 'Mapp.UI/bin/publish/' | |
workflow: '.github/workflows/ci_cd.yml' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.MAPP_PAT }} | |
- name: Install dependencies | |
run: dotnet restore | |
- name: Change assembly versions | |
run: | | |
sed -i 's/AssemblyVersion(".*")/AssemblyVersion("${{env.release_version}}")/g' Mapp.UI/Properties/SharedAssemblyInfo.cs | |
sed -i 's/AssemblyFileVersion(".*")/AssemblyFileVersion("${{env.release_version}}")/g' Mapp.UI/Properties/SharedAssemblyInfo.cs | |
- name: Build | |
run: | | |
dotnet build --configuration Release --no-restore | |
dotnet publish Mapp.UI -c Release -r win-x64 -o ${{env.bin_dir}} -p:PublishSingleFile=true --self-contained false | |
- name: Test | |
run: dotnet test --no-restore --verbosity minimal | |
- name: Set ENV | |
# TODO is it possible to combine output variables in single step? | |
run: | | |
echo "release_tag=v${{env.release_version}}${{github.event.inputs.release_suffix}}" >> $GITHUB_ENV | |
- name: Set ENV 2 | |
run: | | |
echo "artifact_name=mapp_${{env.release_tag}}_binaries.zip" >> $GITHUB_ENV | |
- name: Find Head | |
id: head | |
run: echo "::set-output name=head::$(git rev-parse HEAD)" | |
- name: Find latest tag | |
id: latest_tag | |
run: echo "::set-output name=latest_tag::$(git describe --tags --abbrev=0)" | |
- name: Generate changelog text | |
id: changelog_build | |
uses: mikepenz/[email protected] | |
with: | |
configuration: ".github/workflows/changelog_settings.json" | |
ignorePreReleases: "false" | |
commitMode: "true" | |
toTag: ${{ steps.head.outputs.head }} | |
fromTag: ${{ steps.latest_tag.outputs.latest_tag }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Append to CHANGELOG.md | |
uses: DamianReeves/write-file-action@master | |
with: | |
path: ./CHANGELOG.md | |
contents: \n${{ steps.changelog_build.outputs.changelog }} | |
write-mode: append | |
- name: Check prerelease version | |
uses: haya14busa/action-cond@v1 | |
id: condval | |
with: # allows to get actual bool from string | |
cond: ${{ github.event.inputs.release_suffix != '' }} | |
if_true: true | |
if_false: false | |
- name: Create Archive | |
uses: thedoctor0/zip-release@master | |
with: | |
path: . | |
directory: ${{env.bin_dir}} | |
filename: ${{env.artifact_name}} | |
exclusions: '*.git* *.pdb /*Invoice Converter/* /*Transactions Configs/* ${{env.bin_dir}}Invoice Converter/* ${{env.bin_dir}}Transactions Configs/ ${{env.bin_dir}}Transactions Configs' | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "${{env.bin_dir}}${{env.artifact_name}}" | |
tag: v${{env.release_version}} | |
name: "${{env.release_tag}} - ${{github.event.inputs.release_name}}" | |
allowUpdates: true | |
commit: master | |
omitBody: false | |
omitName: false | |
prerelease: ${{steps.condval.outputs.value}} | |
artifactErrorsFailBuild: true | |
body: ${{ steps.changelog_build.outputs.changelog }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Change default version in workflow | |
# sed to replace only the first occurence | |
run: | | |
sed -i "0,/default: '.*' # major/s//default: '${{github.event.inputs.release_major}}' # major/g" ${{env.workflow}} | |
sed -i "0,/default: '.*' # minor/s//default: '${{github.event.inputs.release_minor}}' # minor/g" ${{env.workflow}} | |
sed -i "0,/(previous .*)/s//(previous ${{github.event.inputs.release_patch}})/g" ${{env.workflow}} | |
- name: Commit report | |
run: | | |
git config --global user.name 'AutomatedRelease' | |
git config --global user.email '[email protected]' | |
git commit -am "chore: Automated report [skip ci]" | |
git push |