Skip to content

Commit

Permalink
CI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling committed May 4, 2024
1 parent 9a32e3d commit 7ac48d1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 87 deletions.
50 changes: 23 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ on:
environment_name:
required: true
type: string
version2_build:
required: true
type: boolean
working_directory:
required: true
type: string
Expand All @@ -21,12 +18,15 @@ on:
build_configuration:
required: true
type: string
binaries_directory:
binaries_root_directory:
required: true
type: string
artifacts_directory:
artifacts_root_directory:
required: true
type: string
artifacts_sub_directories:
required: false
type: string
artifacts_archive_name:
required: true
type: string
Expand Down Expand Up @@ -79,37 +79,33 @@ jobs:
if: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
run: dotnet pack ${{ inputs.project_name }} --configuration ${{ inputs.build_configuration }} --no-build --no-restore

- name: Copy files for deployment
if: ${{ !inputs.version2_build && !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
- name: Copy binaries to artifacts directory
if: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
shell: pwsh
run: |
New-Item -Type Directory -Force ${{ inputs.artifacts_directory }}
Get-ChildItem -Path 'Source/Lib/Trakt.NET/bin/${{ inputs.build_configuration }}' -Recurse | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json|[a-z[A-Z]*.nupkg|[a-z][A-Z]*.snupkg'} | Copy-Item -Destination ${{ inputs.artifacts_directory }}
$filePatterns = "Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json|[a-z[A-Z]*.nupkg|[a-z][A-Z]*.snupkg"
$binariesRootDirectory = "${{ inputs.binaries_root_directory }}/${{ inputs.build_configuration }}"
$artifactsRootDirectory = "${{ inputs.artifacts_root_directory }}"
$hasArtifactsSubDirectories = "${{ inputs.artifacts_sub_directories }}" -ne ""
New-Item -Type Directory -Force $artifactsRootDirectory
Get-ChildItem -Path $binariesRootDirectory -Recurse | Where-Object { $_.Fullname -match $filePatterns } | Copy-Item -Destination $artifactsRootDirectory
if ($hasArtifactsSubDirectories) {
$artifactsSubDirectories = "${{ inputs.artifacts_sub_directories }}" -split ","
foreach ($directory in $artifactsSubDirectories) {
New-Item -Type Directory -Force "$artifactsRootDirectory/$directory"
}
foreach ($directory in $artifactsSubDirectories) {
Get-ChildItem -Path "$binariesRootDirectory/$directory" -Recurse | Where-Object { $_.Fullname -match $filePatterns } | Copy-Item -Destination "$artifactsRootDirectory/$directory"
}
}
- name: Copy files for deployment v2
if: ${{ inputs.version2_build && github.actor != 'dependabot[bot]' }}
shell: pwsh
run: |
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}'
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}/netstandard2.1'
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}/netstandard2.0'
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}/net6.0'
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}/net7.0'
New-Item -Type Directory -Force '${{ inputs.artifacts_directory }}/net8.0'
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}' | Where-Object {$_.Fullname -match '[a-z[A-Z]*.nupkg|[a-z][A-Z]*.snupkg'} | Copy-Item -Destination ${{ inputs.artifacts_directory }}
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}/netstandard2.1' | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json'} | Copy-Item -Destination '${{ inputs.artifacts_directory }}/netstandard2.1'
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}/netstandard2.0' | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json'} | Copy-Item -Destination '${{ inputs.artifacts_directory }}/netstandard2.0'
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}/net6.0' | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json'} | Copy-Item -Destination '${{ inputs.artifacts_directory }}/net6.0'
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}/net7.0' | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json'} | Copy-Item -Destination '${{ inputs.artifacts_directory }}/net7.0'
Get-ChildItem -Path 'src/libs/Trakt.NET/bin/${{ inputs.build_configuration }}/net8.0' | Where-Object {$_.Fullname -match 'Trakt.NET*.dll|Trakt.NET*.xml|Trakt.NET*.pdb|Trakt.NET*.deps.json'} | Copy-Item -Destination '${{ inputs.artifacts_directory }}/net8.0'
- name: Upload artifacts
if: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifacts_archive_name }}-${{ github.run_number }}-${{ github.sha }}
retention-days: 14
path: '${{ inputs.artifacts_directory }}/'
path: '${{ inputs.artifacts_root_directory }}/'

- name: Push NuGet package to Github Package Registry
if: ${{ inputs.push_nuget_package && !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
Expand Down
108 changes: 48 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,98 +12,86 @@ on:
- 'release-**'

jobs:
environment-check:
init:
runs-on: windows-latest
outputs:
environment_name: ${{ steps.find-environment.outputs.environment_name }}
target_branch_name: ${{ steps.find-environment.outputs.target_branch_name }}
deploy_nuget_package: ${{ steps.find-environment.outputs.deploy_nuget_package }}

steps:
- name: Check branch for enviroment
if: github.event_name != 'pull_request'
- name: Initialize environment variables
id: find-environment
shell: bash
run: |
echo "Running on branch ${{ github.ref_name }}"
br_name=${{ github.ref_name }}
echo "target_br_name=${br_name//\//-}" >> "$GITHUB_ENV"
if [[ "${{ github.ref_name }}" == *"main"* ]]; then
echo "env_name=Production" >> "$GITHUB_ENV"
elif [[ "${{ github.ref }}" == "refs/tags/v"* ]]; then
echo "env_name=Production" >> "$GITHUB_ENV"
elif [[ "${{ github.ref_name }}" == *"develop"* ]]; then
echo "env_name=Development" >> "$GITHUB_ENV"
elif [[ "${{ github.ref_name }}" == *"release"* ]]; then
echo "env_name=Release-Previews" >> "$GITHUB_ENV"
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
branch_name=${{ github.ref_name }}
else
echo "env_name=Development" >> "$GITHUB_ENV"
fi
- name: Check branch for enviroment in PR
if: github.event_name == 'pull_request'
shell: bash
run: |
echo "Running on branch ${{ github.head_ref }}"
br_name=${{ github.base_ref }}
echo "target_br_name=${br_name//\//-}" >> "$GITHUB_ENV"
if [[ "${{ github.base_ref }}" == *"main"* ]]; then
echo "env_name=Production" >> "$GITHUB_ENV"
elif [[ "${{ github.ref }}" == "refs/tags/v"* ]]; then
echo "env_name=Production" >> "$GITHUB_ENV"
elif [[ "${{ github.base_ref }}" == *"develop"* ]]; then
echo "env_name=Development" >> "$GITHUB_ENV"
elif [[ "${{ github.base_ref }}" == *"release"* ]]; then
echo "env_name=Release-Previews" >> "$GITHUB_ENV"
branch_name=${{ github.base_ref }}
fi
target_br_name=${branch_name//\//-}
echo "Running on branch: ${branch_name}"
echo "Target branch is: ${target_br_name}"
if [[ "${branch_name}" == *"main"* || "${{ github.ref }}" == "refs/tags/v"* ]]; then
environment=Production
elif [[ "${branch_name}" == *"develop"* ]]; then
environment=Development
elif [[ "${branch_name}" == *"release"* ]]; then
environment=Release-Previews
else
echo "env_name=Development" >> "$GITHUB_ENV"
fi
- name: Output environment
shell: bash
run: |
echo "Environment name = ${{ env.env_name }}"
echo "Branch name = ${{ env.target_br_name }}"
outputs:
environment_name: ${{ env.env_name }}
target_branch_name: ${{ env.target_br_name }}
environment=Development
fi
if [[ "${environment}" == "Production" || "${environment}" == "Release-Previews" ]]; then
echo "deploy_nuget_package=true" >> "$GITHUB_ENV"
echo "NuGet package deployment is enabled"
else
echo "deploy_nuget_package=false" >> "$GITHUB_ENV"
echo "NuGet package deployment is disabled"
fi
echo "Found environment: ${environment}"
echo "environment_name=${environment}" >> "$GITHUB_ENV"
echo "target_branch_name=${target_br_name}" >> "$GITHUB_ENV"
stable:
needs: [environment-check]
needs: [init]
uses: ./.github/workflows/build.yml
secrets: inherit
with:
should_run: true
environment_name: ${{ needs.environment-check.outputs.environment_name }}
version2_build: false
environment_name: ${{ needs.init.outputs.environment_name }}
working_directory: 'Source'
project_name: 'Source/Lib/Trakt.NET/Trakt.NET.csproj'
build_configuration: Release
binaries_directory: 'Source/Lib/Trakt.NET/bin'
artifacts_directory: 'artifacts'
artifacts_archive_name: 'Trakt.NET-CI-Build-${{ needs.environment-check.outputs.target_branch_name }}'
binaries_root_directory: 'Source/Lib/Trakt.NET/bin'
artifacts_root_directory: 'artifacts'
artifacts_archive_name: 'Trakt.NET-CI-Build-${{ needs.init.outputs.target_branch_name }}'
upload_codecov: true
push_nuget_package: true
push_nuget_package: ${{ needs.init.outputs.deploy_nuget_package == 'true' }}

v2-alpha:
needs: [environment-check]
needs: [init]
uses: ./.github/workflows/build.yml
secrets: inherit
with:
should_run: ${{ github.ref_name == 'develop' }}
environment_name: ${{ needs.environment-check.outputs.environment_name }}
version2_build: true
environment_name: ${{ needs.init.outputs.environment_name }}
working_directory: 'src'
project_name: 'src/libs/Trakt.NET/Trakt.NET.csproj'
build_configuration: Release
binaries_directory: 'src/libs/Trakt.NET/bin'
artifacts_directory: 'artifacts-v2.0.0-alpha'
artifacts_archive_name: 'Trakt.NET-CI-Build-v2.0.0-Alpha-${{ needs.environment-check.outputs.target_branch_name }}'
binaries_root_directory: 'src/libs/Trakt.NET/bin'
artifacts_root_directory: 'artifacts-v2.0.0-alpha'
artifacts_sub_directories: 'netstandard2.0,netstandard2.1,net6.0,net7.0,net8.0'
artifacts_archive_name: 'Trakt.NET-CI-Build-v2.0.0-Alpha-${{ needs.init.outputs.target_branch_name }}'
upload_codecov: false
push_nuget_package: false

docs:
needs: [environment-check, stable]
needs: [init, stable]
uses: ./.github/workflows/documentation.yml
secrets: inherit
with:
should_run: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
environment_name: ${{ needs.environment-check.outputs.environment_name }}
environment_name: ${{ needs.init.outputs.environment_name }}
project_name: 'Source/Lib/Trakt.NET/Trakt.NET.csproj'
build_configuration: Release
artifacts_archive_name: 'Trakt.NET-Documentation-${{ needs.environment-check.outputs.target_branch_name }}'
artifacts_archive_name: 'Trakt.NET-Documentation-${{ needs.init.outputs.target_branch_name }}'

0 comments on commit 7ac48d1

Please sign in to comment.