Skip to content

Merge branch 'main' into feature/ci-cd #43

Merge branch 'main' into feature/ci-cd

Merge branch 'main' into feature/ci-cd #43

Workflow file for this run

name: CI/CD Pipeline
on: [push, pull_request, workflow_dispatch]
jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest
outputs:
is_push_to_default_branch: ${{ steps.conditionals_handler.outputs.is_push_to_default_branch }}
steps:
- name: Data gatherer
id: data_gatherer
shell: pwsh
run: |
# Get default branch
$repo = "${{ github.repository }}"
$defaultBranch = Invoke-RestMethod -Method GET -Uri https://api.github.com/repos/$repo | Select-Object -ExpandProperty default_branch
Write-Output "::set-output name=default_branch::$(echo $defaultBranch)"
- name: Conditionals handler
id: conditionals_handler
shell: pwsh
run: |
$defaultBranch = "${{ steps.data_gatherer.outputs.default_branch }}"
$githubRef = "${{ github.ref }}"
$githubEventName = "${{ github.event_name }}"
$isDefaultBranch = 'false'
$isPush = 'false'
$isPushToDefaultBranch = 'false'
if ( $githubRef -like "*$defaultBranch*" ) {
$isDefaultBranch = 'true'
}
if ( $githubEventName -eq 'push' ) {
$isPush = 'true'
}
if ( $githubRef -like "*$defaultBranch*" -and $githubEventName -eq 'push' ) {
$isPushToDefaultBranch = 'true'
}
Write-Output "::set-output name=is_default_branch::$(echo $isDefaultBranch)"
Write-Output "::set-output name=is_push::$(echo $isPush)"
Write-Output "::set-output name=is_push_to_default_branch::$(echo $isPushToDefaultBranch)"
- name: Setup .NET Core
id: setup_dotnet_core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.202
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Build solution
id: build_solution
shell: pwsh
run: |
dotnet build .\Ardalis.ApiEndpoints.sln --configuration Release --output Artifacts
- name: Run unit tests
id: run_unit_tests
shell: pwsh
run: |
dotnet test .\Ardalis.ApiEndpoints.sln --configuration Release
- name: Upload artifacts
id: upload_artifacts
uses: actions/upload-artifact@v2
with:
name: Artifacts
path: Artifacts/
cd:
if: needs.ci.outputs.is_push_to_default_branch == 'true'
name: Continuous Deployment
needs: ci
runs-on: ubuntu-latest
steps:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.202
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Filter changes
id: filter_changes
uses: dorny/paths-filter@v2
with:
filters: |
codeanalyzers:
- 'src/Ardalis.ApiEndpoints.CodeAnalyzers/**'
apiendpoints:
- 'src/Ardalis.ApiEndpoints/**'
- if: steps.filter_changes.outputs.codeanalyzers == 'true'
name: Create and publish ApiEndpoints CodeAnalyzers package to NuGet
id: create_and_publish_codeanalyzer_nupkg
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: src/Ardalis.ApiEndpoints.CodeAnalyzers/Ardalis.ApiEndpoints.CodeAnalyzers.csproj
VERSION_REGEX: <Version>(.*)<\/Version>
TAG_COMMIT: true
TAG_FORMAT: Analyzer_v*
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
- if: steps.filter_changes.outputs.apiendpoints == 'true'
name: Create and publish ApiEndpoints package to NuGet
id: create_and_publish_apiendpoints_nupkg
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: src/Ardalis.ApiEndpoints/Ardalis.ApiEndpoints.csproj
VERSION_REGEX: <Version>(.*)<\/Version>
TAG_COMMIT: true
TAG_FORMAT: v*
NUGET_KEY: ${{secrets.NUGET_API_KEY}}