Skip to content

Commit

Permalink
Add workflows to push nuget packages, and update existing workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnamed434 committed Jul 24, 2024
1 parent 993d026 commit 76738d2
Show file tree
Hide file tree
Showing 15 changed files with 484 additions and 9 deletions.
24 changes: 24 additions & 0 deletions .github/actions/nuget-pack/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'NuGet Pack'
description: 'Packs BitMono NuGet packages'
inputs:
nuspec_path:
description: 'Path to .nuspec'
required: true
nuget_push:
description: 'Push to Nuget?'
required: false
default: false
nuget_key:
description: 'NuGet deploy key'
required: false
runs:
using: "composite"
steps:
- name: Pack
run: nuget pack ${{ inputs.nuspec_path }}
shell: bash
- name: Push to NuGet (Release)
run: if ${{ inputs.nuget_push == 'true' }}; then
dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ inputs.nuget_key }} --source https://api.nuget.org/v3/index.json;
fi
shell: bash
84 changes: 84 additions & 0 deletions .github/actions/project-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: 'Project Build'
description: 'Builds BitMono projects'
inputs:
project_path:
description: 'Path to project folder'
required: true
create_artifacts:
description: 'Creates artifacts'
required: false
target_framework:
description: 'The target framework to build on'
required: true
github_token:
description: 'GitHub token'
required: false
runtime_version:
description: 'Build runtime version default linux-x64'
required: false
default: 'linux-x64'
outputs:
version:
description: "Generated version (SemVersion compatible)"
value: ${{ steps.get-version.outputs.version }}
is_prerelease:
description: 'Gets if the version is a prerelease'
value: ${{ steps.check-prerelease.outputs.is_prerelease }}
runs:
using: "composite"
steps:
# Generate semver compatible version from current tag and commit hash
- name: Create version
id: get-version
run: echo "version=$(git describe --tags `git rev-list --tags --max-count=1`)+$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
shell: bash

- name: Check Prerelease
id: check-prerelease
run: "if ${{ contains(steps.get-version.outputs.version, '-') }}; then
echo is_prerelease=true >> $GITHUB_OUTPUT;
else
echo is_prerelease=false >> $GITHUB_OUTPUT;
fi"
shell: bash

# Set execute permissions for all relevant files and directories
- name: Set execute permissions
run: chmod -R +x $GITHUB_WORKSPACE/
shell: bash

# Commands that are used multiple times.
# Placed in one place to make sure that the arguments would always be the same
- name: Common commands
id: common-commands
run: |
echo "dotnet-restore=dotnet restore \$PROJECT_PATH --runtime ${{ inputs.runtime_version }}" -p:Configuration=Release -p:TargetFramework=${{ inputs.target_framework }} -p:CreateBitMonoArtifacts=${{ inputs.create_artifacts }} >> $GITHUB_OUTPUT
echo "dotnet-build=dotnet build \$PROJECT_PATH --configuration Release --no-restore -p:TargetFramework=${{ inputs.target_framework }} -p:BitMonoVersion=${{ steps.get-version.outputs.version }} --runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
echo "dotnet-test=dotnet test \$PROJECT_PATH --configuration Release --no-restore --no-build -p:TargetFramework=${{ inputs.target_framework }} --runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
shell: bash

# Install dependencies (this needs to be a separate step from build for caching)
- name: Install dependencies
run: |
${{ steps.common-commands.outputs.dotnet-restore }}
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-restore }}'
env:
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
shell: bash

# Build project
- name: Build
run: |
${{ steps.common-commands.outputs.dotnet-build }}
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-build }}'
env:
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
shell: bash

# Test project
- name: Test
run: |
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-test }}'
env:
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Finds all tests projects matching 'BitMono.*.Tests' for a project passed as the first argument
# and runs a command passed as the second argument for every tests project found.
# Also sets PROJECT_PATH environment variables with the value of the tests project folder path.
# Exits with a non-zero status if any command fails.
#
# Example usage:
# pwsh -f .github/actions/project-build/run-command-for-every-tests-project.ps1 "src/BitMono.Core" "echo \$PROJECT_PATH"
#
# Example output:
# Tests project found: /home/runner/work/BitMono/BitMono/tests/BitMono.Core.Tests. Executing a command: ...
# Assumes the first argument is already the path to the tests directory.

$testsFolderPath = $args[0]
$commandToExecute = $args[1]
$global:exitCode = 0

Check warning on line 16 in .github/actions/project-build/run-command-for-every-tests-project.ps1

View check run for this annotation

codefactor.io / CodeFactor

.github/actions/project-build/run-command-for-every-tests-project.ps1#L16

Found global variable 'global:exitCode'. (PSAvoidGlobalVars)

Get-ChildItem -Path $testsFolderPath -Directory -Recurse `
| Where-Object { $_.Name -match "^BitMono\..*\.Tests$" } `
| ForEach-Object {
$testsProjectPath = $_.FullName
Write-Output "Tests project found: $testsProjectPath. Executing a command: $commandToExecute"
bash -c "PROJECT_PATH=$testsProjectPath && $commandToExecute"
if ($LASTEXITCODE -ne 0) {
$global:exitCode = $LASTEXITCODE

Check warning on line 25 in .github/actions/project-build/run-command-for-every-tests-project.ps1

View check run for this annotation

codefactor.io / CodeFactor

.github/actions/project-build/run-command-for-every-tests-project.ps1#L25

Found global variable 'global:exitCode'. (PSAvoidGlobalVars)
}
}

if ($global:exitCode -ne 0) {

Check warning on line 29 in .github/actions/project-build/run-command-for-every-tests-project.ps1

View check run for this annotation

codefactor.io / CodeFactor

.github/actions/project-build/run-command-for-every-tests-project.ps1#L29

Found global variable 'global:exitCode'. (PSAvoidGlobalVars)
exit $global:exitCode

Check warning on line 30 in .github/actions/project-build/run-command-for-every-tests-project.ps1

View check run for this annotation

codefactor.io / CodeFactor

.github/actions/project-build/run-command-for-every-tests-project.ps1#L30

Found global variable 'global:exitCode'. (PSAvoidGlobalVars)
}
39 changes: 39 additions & 0 deletions .github/workflows/BitMono.API.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: BitMono.API

on:
create:
tags:
- "*"
push:
branches: [ master ]
paths:
- '.github/workflows/BitMono.API.yaml'
- 'src/BitMono.API/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/BitMono.API.yaml'
- 'src/BitMono.API/**'

jobs:
build:
name: "BitMono.API Build"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
name: Setup .NET
with:
dotnet-version: 8.x

- uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.API
github_token: ${{ secrets.PAT }}
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
nuget_push: true
10 changes: 8 additions & 2 deletions .github/workflows/BitMono.CLI.Release.net462.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
with:
dotnet-version: 8.x

- name: Build
run: dotnet build ./src/BitMono.CLI/BitMono.CLI.csproj /p:TargetFramework=net462 /p:BitMonoVersion=${{ github.ref_name }} /p:CreateBitMonoArtifacts=true --configuration Release
- name: Build Project
uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.CLI
create_artifacts: true
target_framework: net462
github_token: ${{ secrets.PAT }}

- name: Upload build
uses: actions/upload-artifact@v4
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/BitMono.CLI.Release.net6.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
with:
dotnet-version: 8.x

- name: Build
run: dotnet build ./src/BitMono.CLI/BitMono.CLI.csproj /p:TargetFramework=net6.0 /p:BitMonoVersion=${{ github.ref_name }} /p:CreateBitMonoArtifacts=true --configuration Release
- name: Build Project
uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.CLI
create_artifacts: true
target_framework: net6.0
github_token: ${{ secrets.PAT }}

- name: Upload build
uses: actions/upload-artifact@v4
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/BitMono.CLI.Release.netstandard2.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
with:
dotnet-version: 8.x

- name: Build
run: dotnet build ./src/BitMono.CLI/BitMono.CLI.csproj /p:TargetFramework=netstandard2.0 /p:BitMonoVersion=${{ github.ref_name }} /p:CreateBitMonoArtifacts=true --configuration Release
- name: Build Project
uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.CLI
create_artifacts: true
target_framework: netstandard2.0
github_token: ${{ secrets.PAT }}

- name: Upload build
uses: actions/upload-artifact@v4
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/BitMono.CLI.Release.netstandard2.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.x
dotnet-version: 8.x

- name: Build
run: dotnet build ./src/BitMono.CLI/BitMono.CLI.csproj /p:TargetFramework=netstandard2.1 /p:BitMonoVersion=${{ github.ref_name }} /p:CreateBitMonoArtifacts=true --configuration Release
- name: Build Project
uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.CLI
create_artifacts: true
target_framework: netstandard2.1
github_token: ${{ secrets.PAT }}

- name: Upload build
uses: actions/upload-artifact@v4
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/BitMono.Core.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: BitMono.Core

on:
create:
tags:
- "*"
push:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Core.yaml'
- 'src/BitMono.Core/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Core.yaml'
- 'src/BitMono.Core/**'

jobs:
build:
name: "BitMono.Core Build"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
name: Setup .NET
with:
dotnet-version: 8.x

- uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.Core
github_token: ${{ secrets.PAT }}
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
nuget_push: true
39 changes: 39 additions & 0 deletions .github/workflows/BitMono.Host.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: BitMono.Host

on:
create:
tags:
- "*"
push:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Host.yaml'
- 'src/BitMono.Host/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Host.yaml'
- 'src/BitMono.Host/**'

jobs:
build:
name: "BitMono.Host Build"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
name: Setup .NET
with:
dotnet-version: 8.x

- uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.Host
github_token: ${{ secrets.PAT }}
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
nuget_push: true
39 changes: 39 additions & 0 deletions .github/workflows/BitMono.Obfuscation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: BitMono.Obfuscation

on:
create:
tags:
- "*"
push:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Obfuscation.yaml'
- 'src/BitMono.Obfuscation/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/BitMono.Obfuscation.yaml'
- 'src/BitMono.Obfuscation/**'

jobs:
build:
name: "BitMono.Obfuscation Build"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
name: Setup .NET
with:
dotnet-version: 8.x

- uses: ./.github/actions/project-build
id: project-build
with:
project_path: src/BitMono.Obfuscation
github_token: ${{ secrets.PAT }}
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
nuget_push: true
Loading

0 comments on commit 76738d2

Please sign in to comment.