Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
Updated to remove use of the set-output command
  • Loading branch information
jstedfast committed Oct 15, 2024
1 parent 4df1771 commit c4999af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 81 deletions.
107 changes: 28 additions & 79 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,18 @@ jobs:
SOLUTION_PATH: MailKit.sln
BUILD_PLATFORM: Any CPU
BUILD_CONFIGURATION: ${{ matrix.build-configuration }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GENERATE_CODE_COVERAGE: ${{ matrix.os == 'windows-latest' && matrix.build-configuration == 'Debug' }}
MONO_RUNTIME: ${{ matrix.os != 'windows-latest' }}
PUBLISH: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.os == 'windows-latest' && matrix.build-configuration == 'Release' }}

steps:
- name: Setup/Install the .NET 8 SDK
id: install-netsdk
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Configure build options
id: configure
shell: pwsh
run: |
$IS_DEBUG = 'false'
$IS_RELEASE = 'false'
$IS_PUSH_TO_MASTER = 'false'
$IS_NOT_PR = 'true'
$IS_GITHUB_RELEASE = 'false'
$IS_WINDOWS = 'false'
$IS_UBUNTU = 'false'
$GENERATE_CODE_COVERAGE = 'no'
if ( $env:BUILD_CONFIGURATION -ceq 'Debug' ) {
$IS_DEBUG = 'true'
}
if ( $env:BUILD_CONFIGURATION -ceq 'Release' ) {
$IS_RELEASE = 'true'
}
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') ) {
$IS_PUSH_TO_MASTER = 'true'
}
if ( $env:GITHUB_EVENT_NAME -ceq 'pull_request' ) {
$IS_NOT_PR = 'false'
}
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') -and ($env:BUILD_CONFIGURATION -ceq 'Release') -and ($env:OS -ceq 'windows-latest') ) {
$IS_GITHUB_RELEASE = 'true'
}
if ( $env:OS -ceq 'windows-latest' ) {
$IS_WINDOWS = 'true'
}
if ( $env:OS -ceq 'ubuntu-latest' ) {
$IS_UBUNTU = 'true'
}
if ( $IS_WINDOWS -ceq 'true' -and $IS_DEBUG -ceq 'true' ) {
$GENERATE_CODE_COVERAGE = 'yes'
}
echo "::set-output name=IS_DEBUG::$(echo $IS_DEBUG)"
echo "::set-output name=IS_RELEASE::$(echo $IS_RELEASE)"
echo "::set-output name=is_push_to_master::$(echo $IS_PUSH_TO_MASTER)"
echo "::set-output name=is_not_pr::$(echo $IS_NOT_PR)"
echo "::set-output name=is_github_release::$(echo $IS_GITHUB_RELEASE)"
echo "::set-output name=is_windows::$(echo $IS_WINDOWS)"
echo "::set-output name=is_ubuntu::$(echo $IS_UBUNTU)"
echo "::set-output name=generate_code_coverage::$(echo $GENERATE_CODE_COVERAGE)"
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
OS: ${{ matrix.os }}

- if: steps.configure.outputs.is_windows == 'true'
- if: runner.os == 'Windows'
name: Setup MSBuild
id: setup_msbuild
uses: microsoft/[email protected]
Expand All @@ -94,20 +46,28 @@ jobs:
run: |
$xml = [xml](gc MailKit/MailKit.csproj)
$SEMANTIC_VERSION_NUMBER = $xml.Project.PropertyGroup.VersionPrefix
echo "::set-output name=version_num::$(echo $SEMANTIC_VERSION_NUMBER[0].Trim())"
echo "::set-output name=version_tag::$(echo v"$SEMANTIC_VERSION_NUMBER[0].Trim()")"
$VERSION_NUM = $SEMANTIC_VERSION_NUMBER[0].Trim()
Write-Host "version_num=${VERSION_NUM}"
Write-Host "version_tag=v${VERSION_NUM}"
[IO.File]::AppendAllText($env:GITHUB_OUTPUT, "version_num=${VERSION_NUM}$([Environment]::NewLine)")
[IO.File]::AppendAllText($env:GITHUB_OUTPUT, "version_tag=v${VERSION_NUM}$([Environment]::NewLine)")
- if: steps.configure.outputs.is_github_release == 'true'
- if: ${{ env.PUBLISH == 'true' }}
name: Get latest tag
id: get_latest_tag
shell: pwsh
run: |
$LATEST_TAG = git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "https://github.com/$env:GIT_URL.git" '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3
echo "::set-output name=tag::$(echo $LATEST_TAG)"
Write-Host "tag=$LATEST_TAG"
[IO.File]::AppendAllText($env:GITHUB_OUTPUT, "tag=${LATEST_TAG}$([Environment]::NewLine)")
env:
GIT_URL: ${{ github.repository }}

- if: steps.configure.outputs.is_github_release == 'true' && steps.semantic_version.outputs.version_tag != steps.get_latest_tag.outputs.tag
- if: ${{ env.PUBLISH == 'true' && steps.semantic_version.outputs.version_tag != steps.get_latest_tag.outputs.tag }}
name: Add new tag to repo
id: add_new_tag_to_repo
continue-on-error: true
Expand All @@ -122,12 +82,6 @@ jobs:
GIT_USER_EMAIL: ${{ github.event.head_commit.author.email }}
NEW_VERSION_NUM: ${{ steps.semantic_version.outputs.version_num }}

- name: Run NuGet restore
id: run_nuget_restore
shell: pwsh
run: |
nuget restore $env:SOLUTION_PATH
- name: Run .NET restore
shell: pwsh
run: |
Expand All @@ -143,29 +97,24 @@ jobs:
continue-on-error: true
shell: pwsh
run: |
dotnet msbuild $env:SOLUTION_PATH -property:Platform=$env:BUILD_PLATFORM -property:Configuration=$env:BUILD_CONFIGURATION -property:MonoRuntime=$env:IS_UBUNTU
env:
IS_UBUNTU: ${{ steps.configure.outputs.is_ubuntu }}
dotnet msbuild $env:SOLUTION_PATH -property:Platform=$env:BUILD_PLATFORM -property:Configuration=$env:BUILD_CONFIGURATION -property:MonoRuntime=$env:MONO_RUNTIME
- name: Run unit tests
id: run_unit_tests
continue-on-error: true
shell: pwsh
run: |
& ./scripts/test.ps1 -Configuration:$env:BUILD_CONFIGURATION -GenerateCodeCoverage:$env:GENERATE_CODE_COVERAGE
env:
BUILD_CONFIGURATION: ${{ matrix.build-configuration }}
GENERATE_CODE_COVERAGE: ${{ steps.configure.outputs.generate_code_coverage }}
- name: Upload unit test results
id: upload_test_results
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}-${{ matrix.os }}-${{ matrix.build-configuration }}-TestResults.xml
name: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ github.run_number }}-${{ matrix.os }}-${{ matrix.build-configuration }}-TestResults.xml
path: TestResult.xml

- if: steps.configure.outputs.generate_code_coverage == 'yes'
- if: ${{ env.GENERATE_CODE_COVERAGE == 'yes' }}
name: Upload code coverage data to coveralls.io
id: upload_to_coveralls
shell: pwsh
Expand All @@ -178,9 +127,9 @@ jobs:
GIT_ACTOR: ${{ github.event.head_commit.author.username }}
GIT_ACTOR_EMAIL: ${{ github.event.head_commit.author.email }}
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COVERALLS_JOB_ID: ${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}
COVERALLS_JOB_ID: ${{ steps.semantic_version.outputs.version_num }}.${{ github.run_number }}

- if: steps.configure.outputs.is_github_release == 'true'
- if: ${{ env.PUBLISH == 'true' }}
name: Create NuGet package
id: create_nuget_package
shell: pwsh
Expand All @@ -190,7 +139,7 @@ jobs:
env:
LATEST_VERSION: ${{ steps.semantic_version.outputs.version_num }}

- if: steps.configure.outputs.is_github_release == 'true'
- if: ${{ env.PUBLISH == 'true' }}
name: Push NuGet package to MyGet
id: push_nuget_package
shell: pwsh
Expand All @@ -199,15 +148,15 @@ jobs:
-ApiKey $env:MYGET_API_KEY `
-Source https://www.myget.org/F/mimekit/api/v3/index.json
env:
NUGET_PKG_PATH: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
NUGET_PKG_PATH: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ github.run_number }}.nupkg
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}

- if: steps.configure.outputs.is_github_release == 'true'
- if: ${{ env.PUBLISH == 'true' }}
name: Upload NuGet package as artifact
id: upload_nuget_package
uses: actions/upload-artifact@v4
with:
name: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
path: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
name: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ github.run_number }}.nupkg
path: MailKit.${{ steps.semantic_version.outputs.version_num }}.${{ github.run_number }}.nupkg

# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)
4 changes: 2 additions & 2 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ param (
[string]
$Configuration = "Debug",
[string]
$GenerateCodeCoverage = "no"
$GenerateCodeCoverage = "false"
)

Write-Output "Configuration: $Configuration"
Expand All @@ -26,7 +26,7 @@ $targetFramework = $project.SelectSingleNode("/Project/PropertyGroup/TargetFrame
$OutputDir = Join-Path "UnitTests" "bin" $Configuration $targetFramework.InnerText
$UnitTestsAssembly = Join-Path $OutputDir "UnitTests.dll"

if ($GenerateCodeCoverage -eq 'yes') {
if ($GenerateCodeCoverage -eq 'true') {
Write-Output "Instrumenting code..."

& dotnet AltCover -i="$OutputDir" --inplace -s="System.*" -s="Microsoft.*" -s="Newtonsoft.*" -s="BouncyCastle.*" -s="MimeKit" -s="NUnit*" -s="AltCover.*" -s="testhost" -s="UnitTests"
Expand Down

0 comments on commit c4999af

Please sign in to comment.