Skip to content

Commit

Permalink
updated pipeline. use github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
stee1 committed Dec 25, 2020
1 parent 6d8eeb9 commit 2f385f5
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 50 deletions.
7 changes: 4 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
/.git
/.gitignore
/.dockerignore
/doc
/docs
/dist
/obj
/Dockerfile*
/docker-compose*.yml
/docker/Dockerfile*
/docker/docker-compose*.yml
/*.sh
/*.ps1
/*.nuspec
/*.nupkg
/*.userprefs
/*.md
/.github
47 changes: 47 additions & 0 deletions .github/workflows/ci-pip-services3-datadog-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Pip.Services Datadog toolkit in .NET

on:
push:
paths:
- '**'
- '!README.md'

jobs:
Default:
runs-on: ubuntu-16.04
if: "!contains(github.event.head_commit.message, '[skip-ci]')"
steps:
- uses: actions/checkout@main

############# Prepare #############

- name: Install prereq and save build number
id: build_info
uses: pip-devops/actions/dotnet/prepare@v1

############# Build and test #############

- name: Build the component
uses: pip-devops/actions/dotnet/build@v1

- name: Test the component
uses: pip-devops/actions/dotnet/test@v1

############# Release #############

- name: Tag branch with the build number
uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
tag: "v${{ steps.build_info.outputs.component_version }}-${{ steps.build_info.outputs.build_number }}"

- name: Release binary artifacts
uses: pip-devops/actions/dotnet/release@v1
with:
nuget-key: ${{ secrets.NUGET_KEY }}

############# Clear #############

- name: Clean up
uses: pip-devops/actions/dotnet/clear@v1

18 changes: 15 additions & 3 deletions build.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"

$component = Get-Content -Path "component.json" | ConvertFrom-Json
$image="$($component.registry)/$($component.name):$($component.version)-build"

# Get buildnumber from github actions
if ($env:GITHUB_RUN_NUMBER -ne $null) {
$component.build = $env:GITHUB_RUN_NUMBER
Set-Content -Path "component.json" -Value $($component | ConvertTo-Json)
}

$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build"
$container=$component.name

# Remove build files
Expand All @@ -13,9 +20,14 @@ if (Test-Path "obj") {
}

# Build docker image
docker build -f docker/Dockerfile.build -t $image .
docker build -f docker/Dockerfile.build -t $buildImage .

# Create and copy compiled files, then destroy
docker create --name $container $image
docker create --name $container $buildImage
docker cp "$($container):/obj" ./obj
docker rm $container

if (!(Test-Path ./obj)) {
Write-Host "obj folder doesn't exist in root dir. Build failed. Watch logs above."
exit 1
}
35 changes: 11 additions & 24 deletions clean.ps1
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
#!/usr/bin/env pwsh

$component = Get-Content -Path "component.json" | ConvertFrom-Json
$buildImage="$($component.registry)/$($component.name):$($component.version)-build"
$testImage="$($component.registry)/$($component.name):$($component.version)-test"
$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build"
$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test"
$docsImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs"

# Clean up build directories
if (Test-Path "obj") {
Remove-Item -Recurse -Force -Path "obj"
}
if (Test-Path "dist") {
Remove-Item -Recurse -Force -Path "dist"
}
if (Test-Path "src/bin") {
Remove-Item -Recurse -Force -Path "src/bin"
}
if (Test-Path "src/obj") {
Remove-Item -Recurse -Force -Path "src/obj"
}
if (Test-Path "test/bin") {
Remove-Item -Recurse -Force -Path "test/bin"
}
if (Test-Path "test/obj") {
Remove-Item -Recurse -Force -Path "test/obj"
}
if (Test-Path "*.nupkg") {
Remove-Item -Force -Path "*.nupkg"
}
Get-ChildItem -Path "." -Include "obj" -Recurse | foreach($_) { Remove-Item -Force -Recurse $_.FullName }

# Remove docker images
docker rmi $buildImage --force
docker rmi $testImage --force
docker rmi $docsImage --force
docker image prune --force
docker rmi -f $(docker images -f "dangling=true" -q) # remove build container if build fails

# Remove existed containers
docker ps -a | Select-String -Pattern "Exit" | foreach($_) { docker rm $_.ToString().Split(" ")[0] }
$exitedContainers = docker ps -a | Select-String -Pattern "Exit"
foreach($c in $exitedContainers) { docker rm $c.ToString().Split(" ")[0] }

# Remove unused volumes
docker volume rm -f $(docker volume ls -f "dangling=true")
Empty file modified component.conf.ps1
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "pip-services3-datadog",
"registry": "pipdevs",
"version": "3.0.0",
"build": "0"
"build": 0
}
30 changes: 30 additions & 0 deletions docgen.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env pwsh

##Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"

# Generate image and container names using the data in the "component.json" file
$component = Get-Content -Path "component.json" | ConvertFrom-Json

$docImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs"
$container=$component.name

# Remove build files
if (Test-Path "./docs") {
Remove-Item -Recurse -Force -Path "./docs/*"
} else {
New-Item -ItemType Directory -Force -Path "./docs"
}

# Build docker image
docker build -f docker/Dockerfile.docgen -t $docImage .

# Create and copy compiled files, then destroy the container
docker create --name $container $docImage
docker cp "$($container):/dotnet/app/html/." ./docs
docker rm $container

if (!(Test-Path "./docs")) {
Write-Host "docs folder doesn't exist in root dir. Build failed. Watch logs above."
exit 1
}
4 changes: 1 addition & 3 deletions docker/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Build stage
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

# set working directory
WORKDIR /app
Expand All @@ -15,4 +14,3 @@ COPY . .

# Publish
RUN dotnet publish src/src.csproj -o /obj -f netstandard2.1

8 changes: 8 additions & 0 deletions docker/Dockerfile.docgen
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM tsgkadot/docker-doxygen

# Set working directory
WORKDIR /app

COPY . .

RUN doxygen Doxyfile
3 changes: 1 addition & 2 deletions docker/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Build stage
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

# set working directory
WORKDIR /app
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ services:
context: ..
dockerfile: docker/Dockerfile.test
image: ${IMAGE:-pipdevs/test}

4 changes: 2 additions & 2 deletions release.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $package = (Get-ChildItem -Path "../dist/*.$version.nupkg").FullName

# Push to nuget repo
if ($env:NUGET_KEY -ne $null) {
dotnet nuget push $package -s https://www.nuget.org/api/v2/package -k $env:NUGET_KEY
dotnet nuget push $package -s https://www.nuget.org/api/v2/package -k $env:NUGET_KEY --skip-duplicate
} else {
nuget push $package -Source https://www.nuget.org/api/v2/package
nuget push $package -Source https://www.nuget.org/api/v2/package --skip-duplicate
}
10 changes: 0 additions & 10 deletions tag.ps1

This file was deleted.

6 changes: 5 additions & 1 deletion test.ps1
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ try {
# Workaround to remove dangling images
docker-compose -f ./docker/docker-compose.test.yml down

##docker build -f docker/Dockerfile.test -t ${IMAGE} .
docker-compose -f ./docker/docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test

# Save the result to avoid overwriting it with the "down" command below
$exitCode = $LastExitCode
} finally {
# Workaround to remove dangling images
docker-compose -f ./docker/docker-compose.test.yml down
}

# Return the exit code of the "docker-compose.test.yml up" command
exit $exitCode

0 comments on commit 2f385f5

Please sign in to comment.