Skip to content

Commit

Permalink
Implement CI/Release flow similar to base package (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattletw authored Jul 16, 2021
1 parent 70a9dfd commit c10026a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 49 deletions.
47 changes: 15 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,22 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set Variables
run: |
echo "DEPLOY_PACKAGE_URL=https://www.myget.org/F/automapperdev/api/v3/index.json" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "DEPLOY_PACKAGE_API_KEY=${{ secrets.MYGET_CI_API_KEY }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "REPO=${{ github.repository }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "REPO_OWNER=${{ github.repository_owner }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --no-restore --verbosity normal

- name: Pack and push AutoMapper.EF6
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Push to MyGet
env:
PROJECT_NAME: AutoMapper.EF6
run: ./Pack_Push.ps1
NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json
NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }}
run: ./Push.ps1
shell: pwsh

# - name: Pack and push AutoMapper.AspNet.OData.EF6
# env:
# PROJECT_NAME: AutoMapper.AspNet.OData.EF6
# run: ./Pack_Push.ps1
# shell: pwsh

# - name: Pack and push AutoMapper.AspNetCore.OData.EF6
# env:
# PROJECT_NAME: AutoMapper.AspNetCore.OData.EF6
# run: ./Pack_Push.ps1
# shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts/**/*
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
tags:
- '*.*.*'
jobs:
build:
strategy:
fail-fast: false
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Push to MyGet
env:
NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json
NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }}
run: ./Push.ps1
shell: pwsh
- name: Push to NuGet
env:
NUGET_URL: https://api.nuget.org/v3/index.json
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: ./Push.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts/**/*
35 changes: 35 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Taken from psake https://github.com/psake/psake

<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}

$artifacts = ".\artifacts"

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

exec { & dotnet clean -c Release }

exec { & dotnet build -c Release }

exec { & dotnet test -c Release -r $artifacts --no-build -l trx --verbosity=normal }

exec { & dotnet pack .\src\AutoMapper.EF6\AutoMapper.EF6.csproj -c Release -o $artifacts --no-build }
17 changes: 0 additions & 17 deletions Pack_Push.ps1

This file was deleted.

14 changes: 14 additions & 0 deletions Push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$scriptName = $MyInvocation.MyCommand.Name
$artifacts = "./artifacts"

if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
} else {
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($scriptName): Pushing $($_.Name)"
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
}

0 comments on commit c10026a

Please sign in to comment.