Skip to content

Commit c10026a

Browse files
authored
Implement CI/Release flow similar to base package (#31)
1 parent 70a9dfd commit c10026a

5 files changed

Lines changed: 100 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,22 @@ jobs:
1212
runs-on: windows-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
16+
- name: Checkout
17+
uses: actions/checkout@v2
1618
with:
1719
fetch-depth: 0
18-
19-
- name: Set Variables
20-
run: |
21-
echo "DEPLOY_PACKAGE_URL=https://www.myget.org/F/automapperdev/api/v3/index.json" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
22-
echo "DEPLOY_PACKAGE_API_KEY=${{ secrets.MYGET_CI_API_KEY }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
23-
echo "REPO=${{ github.repository }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
24-
echo "REPO_OWNER=${{ github.repository_owner }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
25-
- name: Restore
26-
run: dotnet restore
27-
28-
- name: Build
29-
run: dotnet build --configuration Release --no-restore
30-
31-
- name: Test
32-
run: dotnet test --no-restore --verbosity normal
33-
34-
- name: Pack and push AutoMapper.EF6
20+
- name: Build and Test
21+
run: ./Build.ps1
22+
shell: pwsh
23+
- name: Push to MyGet
3524
env:
36-
PROJECT_NAME: AutoMapper.EF6
37-
run: ./Pack_Push.ps1
25+
NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json
26+
NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }}
27+
run: ./Push.ps1
3828
shell: pwsh
39-
40-
# - name: Pack and push AutoMapper.AspNet.OData.EF6
41-
# env:
42-
# PROJECT_NAME: AutoMapper.AspNet.OData.EF6
43-
# run: ./Pack_Push.ps1
44-
# shell: pwsh
45-
46-
# - name: Pack and push AutoMapper.AspNetCore.OData.EF6
47-
# env:
48-
# PROJECT_NAME: AutoMapper.AspNetCore.OData.EF6
49-
# run: ./Pack_Push.ps1
50-
# shell: pwsh
29+
- name: Artifacts
30+
uses: actions/upload-artifact@v2
31+
with:
32+
name: artifacts
33+
path: artifacts/**/*

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.*.*'
7+
jobs:
8+
build:
9+
strategy:
10+
fail-fast: false
11+
runs-on: windows-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Build and Test
18+
run: ./Build.ps1
19+
shell: pwsh
20+
- name: Push to MyGet
21+
env:
22+
NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json
23+
NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }}
24+
run: ./Push.ps1
25+
shell: pwsh
26+
- name: Push to NuGet
27+
env:
28+
NUGET_URL: https://api.nuget.org/v3/index.json
29+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
30+
run: ./Push.ps1
31+
shell: pwsh
32+
- name: Artifacts
33+
uses: actions/upload-artifact@v2
34+
with:
35+
name: artifacts
36+
path: artifacts/**/*

Build.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Taken from psake https://github.com/psake/psake
2+
3+
<#
4+
.SYNOPSIS
5+
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
6+
to see if an error occcured. If an error is detected then an exception is thrown.
7+
This function allows you to run command-line programs without having to
8+
explicitly check the $lastexitcode variable.
9+
.EXAMPLE
10+
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
11+
#>
12+
function Exec
13+
{
14+
[CmdletBinding()]
15+
param(
16+
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
17+
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
18+
)
19+
& $cmd
20+
if ($lastexitcode -ne 0) {
21+
throw ("Exec: " + $errorMessage)
22+
}
23+
}
24+
25+
$artifacts = ".\artifacts"
26+
27+
if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }
28+
29+
exec { & dotnet clean -c Release }
30+
31+
exec { & dotnet build -c Release }
32+
33+
exec { & dotnet test -c Release -r $artifacts --no-build -l trx --verbosity=normal }
34+
35+
exec { & dotnet pack .\src\AutoMapper.EF6\AutoMapper.EF6.csproj -c Release -o $artifacts --no-build }

Pack_Push.ps1

Lines changed: 0 additions & 17 deletions
This file was deleted.

Push.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$scriptName = $MyInvocation.MyCommand.Name
2+
$artifacts = "./artifacts"
3+
4+
if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
5+
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
6+
} else {
7+
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
8+
Write-Host "$($scriptName): Pushing $($_.Name)"
9+
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY
10+
if ($lastexitcode -ne 0) {
11+
throw ("Exec: " + $errorMessage)
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)