Skip to content

Commit

Permalink
Refresh CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigas002 committed Nov 24, 2023
1 parent 01a0110 commit 1761194
Show file tree
Hide file tree
Showing 13 changed files with 792 additions and 174 deletions.
21 changes: 21 additions & 0 deletions .github/actions/push-nupkg/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Push nupkg'
description: 'Pushes nuget package to feed'
inputs:
publish-base:
description: 'Directory with publish artifacts (nupkgs/snupkgs)'
api-key:
description: 'API key'
package-feed:
description: 'Package feed'

runs:
using: "composite"
steps:
- id: dotnet-nuget-push
run: |
foreach($file in (Get-ChildItem "${{inputs.publish-base}}/" -Recurse -Include *.nupkg))
{
dotnet nuget push $file -k "${{inputs.api-key}}" -s "${{inputs.package-feed}}" --skip-duplicate
}
shell: pwsh
58 changes: 58 additions & 0 deletions .github/actions/read-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# refer to read_version.ps1 for standalone script

name: 'Read version'
description: 'Reads version prefix and suffix'
inputs:
build-props-path:
description: 'Path to Directory.Build.props file'
required: false
type: string
default: 'Directory.Build.props'
continious-tag:
description: 'Tag for conrinious docker builds'
required: false
type: string
default: 'latest'
outputs:
prefix:
description: 'Version prefix'
value: ${{steps.version.outputs.prefix}}
suffix:
description: 'Version suffix'
value: ${{steps.version.outputs.suffix}}
build:
description: 'Build number, taken from AssemblyVersion'
value: ${{steps.version.outputs.build}}
docker-tag:
description: 'Latest for ci, vprefix for release'
value: ${{steps.version.outputs.docker-tag}}

runs:
using: "composite"
steps:
- id: version
run: |
$path = "${{inputs.build-props-path}}"
Set-Variable VersionPrefixPath -Option ReadOnly -Value "/Project/PropertyGroup/VersionPrefix"
Set-Variable VersionSuffixPath -Option ReadOnly -Value "/Project/PropertyGroup/VersionSuffix"
Set-Variable AssemblyVersionPath -Option ReadOnly -Value "/Project/PropertyGroup/AssemblyVersion"
$versionPrefix = (Select-Xml -Path "$path" -XPath $VersionPrefixPath).Node.InnerText
$versionSuffix = (Select-Xml -Path "$path" -XPath $VersionSuffixPath).Node.InnerText
$assemblyVersion = (Select-Xml -Path "$path" -XPath $AssemblyVersionPath).Node.InnerText
$buildVersion = $assemblyVersion.Split('.')[-1]
$dockerTag = ""
if ("$versionSuffix") {
$dockerTag = "${{inputs.continious-tag}}"
}
else {
$dockerTag = "v$versionPrefix"
}
Write-Output "prefix=$versionPrefix" >> $env:GITHUB_OUTPUT
Write-Output "suffix=$versionSuffix" >> $env:GITHUB_OUTPUT
Write-Output "build=$buildVersion" >> $env:GITHUB_OUTPUT
Write-Output "docker-tag=$dockerTag" >> $env:GITHUB_OUTPUT
shell: pwsh
Empty file.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: build
on:
workflow_dispatch:
inputs:
runs-on:
description: 'The operating system to run the job on'
required: true
type: choice
options:
- ubuntu-latest
- windows-latest
- macos-latest
dotnet-version:
description: 'dotnet sdk version'
required: false
type: string
default: '8.x'
workflow_call:
inputs:
runs-on:
description: 'The operating system to run the job on'
required: true
type: string
dotnet-version:
description: 'dotnet sdk version'
required: false
type: string
default: '8.x'

jobs:

build:
runs-on: ${{inputs.runs-on}}
steps:
- uses: actions/checkout@v4

- name: dotnet-setup
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{inputs.dotnet-version}}

- name: dotnet-restore
run: dotnet restore

- name: dotnet-build
run: dotnet build --no-restore -c Release
30 changes: 30 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "codeql"

on:
pull_request:
push:
branches:
- master

concurrency:
group: "codeql"
cancel-in-progress: false

jobs:
analyze:
name: analyze
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: init-codeql
uses: github/codeql-action/init@v2
with:
languages: csharp

- name: autobuild
uses: github/codeql-action/autobuild@v2

- name: codeql-analyze
uses: github/codeql-action/analyze@v2
148 changes: 148 additions & 0 deletions .github/workflows/deploy-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: deploy-binaries
on:
workflow_dispatch:
inputs:
runs-on:
description: 'The operating system to run the job on'
required: true
type: choice
options:
- ubuntu-latest
- windows-latest
- macos-latest
projects:
description: 'Array of projects to publish'
required: true
type: string
publish-base:
description: 'Base path to publish artifact'
required: false
type: string
default: 'publish'
continious-tag:
description: 'Tag name for continious builds'
required: false
type: string
default: 'continious'
dotnet-version:
description: 'dotnet sdk version'
required: false
type: string
default: '8.x'
build-props-path:
description: 'Path to Directory.Build.props file'
required: false
type: string
default: 'Directory.Build.props'
workflow_call:
inputs:
runs-on:
description: 'The operating system to run the job on'
required: true
type: string
projects:
description: 'Array of projects to publish'
required: true
type: string
publish-base:
description: 'Base path to publish artifact'
required: false
type: string
default: 'publish'
continious-tag:
description: 'Tag name for continious builds'
required: false
type: string
default: 'continious'
dotnet-version:
description: 'dotnet sdk version'
required: false
type: string
default: '8.x'
build-props-path:
description: 'Path to Directory.Build.props file'
required: false
type: string
default: 'Directory.Build.props'

jobs:

deploy:
runs-on: ${{inputs.runs-on}}
defaults:
run:
shell: pwsh
env:
rid: ''
tag: ''
prerelease: true
project-name: ''
publish-path: ''
artifact-path: ''
strategy:
matrix:
project: ${{fromJson(inputs.projects)}}
steps:
- uses: actions/checkout@v4

- name: set-env
run: |
$rid = ""
switch ($true) {
$IsWindows { $rid = "win-x64"; break }
$IsLinux { $rid = "linux-x64"; break }
$IsMacOS { $rid = "osx-x64"; break }
}
Write-Output "rid=$rid" >> $env:GITHUB_ENV
$projectName = Split-Path -Path "${{matrix.project}}" -Leaf -Resolve | Split-Path -LeafBase
$publishPath = "${{inputs.publish-base}}/$projectName/$rid"
$artifactPath = "${{inputs.publish-base}}/${projectName}_$rid.zip"
Write-Output "project-name=$projectName" >> $env:GITHUB_ENV
Write-Output "publish-path=$publishPath" >> $env:GITHUB_ENV
Write-Output "artifact-path=$artifactPath" >> $env:GITHUB_ENV
- name: read-version
id: read-version
uses: ./.github/actions/read-version
with:
build-props-path: ${{inputs.build-props-path}}

- name: set-deploy-properties
run: |
if ("${{steps.read-version.outputs.suffix}}")
{
Write-Output "tag=${{inputs.continious-tag}}" >> $env:GITHUB_ENV
Write-Output "prerelease=true" >> $env:GITHUB_ENV
}
else
{
Write-Output "tag=v${{steps.read-version.outputs.prefix}}" >> $env:GITHUB_ENV
Write-Output "prerelease=false" >> $env:GITHUB_ENV
}
- name: dotnet-setup
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{inputs.dotnet-version}}

- name: dotnet-publish
run: dotnet publish "${{matrix.project}}" -c Release -r "${{env.rid}}" -o "${{env.publish-path}}" --sc false

- name: copy-docs
run: |
Copy-Item "*.md" "${{env.publish-path}}/"
Remove-Item "${{env.publish-path}}/*.pdb"
- name: zip-artifacts
run: Compress-Archive -Path "${{env.publish-path}}/*" -Destination "${{env.artifact-path}}"

- name: deploy-binaries
uses: softprops/action-gh-release@v1
with:
tag_name: ${{env.tag}}
generate_release_notes: ${{env.prerelease == 'false'}}
files: ${{env.artifact-path}}
token: ${{secrets.GITHUB_TOKEN}}
prerelease: ${{env.prerelease}}

89 changes: 89 additions & 0 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: deploy-docker
on:
workflow_call:
inputs:
runs-on:
description: 'The operating system to run the job on'
required: true
type: string
registry:
description: 'Registry to push image'
required: true
type: string
project:
description: 'String in ProjectName---DockerfilePath format'
required: true
type: string
build-props-path:
description: 'Path to Directory.Build.props file'
required: false
type: string
default: 'Directory.Build.props'
continious-tag:
description: 'Tag for conrinious docker builds'
required: false
type: string
default: 'latest'
username:
description: 'Username on publishing platform'
required: true
type: string
secrets:
TOKEN:
required: true

jobs:
deploy:
runs-on: ${{inputs.runs-on}}
defaults:
run:
shell: pwsh
env:
image: ''
project: ''
dockerfile: ''
steps:
- uses: actions/checkout@v4

- name: set-project-name-dockerfile
run: |
$project = "${{inputs.project}}".Split("---")[0]
$dockerfile = "${{inputs.project}}".Split("---")[1]
Write-Output "project=$project" >> $env:GITHUB_ENV
Write-Output "dockerfile=$dockerfile" >> $env:GITHUB_ENV
- name: read-version
id: read-version
uses: ./.github/actions/read-version
with:
build-props-path: ${{inputs.build-props-path}}
continious-tag: ${{inputs.continious-tag}}

- name: set-image
run: |
$image = "${{inputs.registry}}/${{inputs.username}}/${{env.project}}"
Write-Output "image=$image" >> $env:GITHUB_ENV
- name: docker-login
uses: docker/login-action@v3
with:
registry: ${{inputs.registry}}
username: ${{inputs.username}}
password: ${{secrets.TOKEN}}

- name: docker-extract-meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{env.image}}
tags: type=raw,value=${{steps.read-version.outputs.docker-tag}}

- name: docker-build-push
uses: docker/build-push-action@v5
with:
context: .
file: ${{env.dockerfile}}
push: ${{github.event_name != 'pull_request'}}
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}

Loading

0 comments on commit 1761194

Please sign in to comment.