-
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (112 loc) · 4.3 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Build
on:
push:
branches:
- main
tags:
- '*'
paths-ignore:
- README.md
- LICENSE
- docs/**
pull_request:
branches:
- main
paths-ignore:
- README.md
- LICENSE
- docs/**
jobs:
Build:
runs-on: ubuntu-latest
env:
buildConfiguration: 'Release'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
IMAGE_NAME: 'azure-devops-cleaner'
DOCKER_BUILDKIT: 1 # Enable Docker BuildKit
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for GitVersion
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/[email protected]
with:
useConfigFile: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
- name: Test
run: dotnet test -c $buildConfiguration --verbosity normal --collect "Code coverage"
- name: Publish
run: |
dotnet publish \
$GITHUB_WORKSPACE/Tingle.AzdoCleaner/Tingle.AzdoCleaner.csproj \
-c $buildConfiguration \
-o $GITHUB_WORKSPACE/drop/Tingle.AzdoCleaner
- name: Replace tokens
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/main.bicep"]'
- name: Build bicep file
uses: azure/CLI@v1
with:
azcliversion: 2.45.0 # somehow 2.46.0 is failing
inlineScript: |
cp $GITHUB_WORKSPACE/main.bicep $GITHUB_WORKSPACE/drop/main.bicep
az bicep build --file main.bicep --outfile $GITHUB_WORKSPACE/drop/main.json
- name: Pull Docker base image & warm Docker cache
run: docker pull "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
- name: Build image
run: |
docker build \
-f Tingle.AzdoCleaner/Dockerfile \
--label com.github.image.run.id=$GITHUB_RUN_ID \
--label com.github.image.run.number=$GITHUB_RUN_NUMBER \
--label com.github.image.job.id=$GITHUB_JOB \
--label com.github.image.source.sha=$GITHUB_SHA \
--label com.github.image.source.branch=$GITHUB_REF \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR" \
--cache-from ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
.
- name: Log into registry
if: ${{ (github.ref == 'refs/heads/main') || (!startsWith(github.ref, 'refs/pull')) || startsWith(github.ref, 'refs/tags') }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image (latest, ShortSha)
if: ${{ (github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags') }}
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA"
- name: Push image (NuGetVersionV2)
if: ${{ !startsWith(github.ref, 'refs/pull') }}
run: docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2"
- name: Push image (major, minor)
if: startsWith(github.ref, 'refs/tags')
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR"
- name: Publish Artifact
uses: actions/upload-artifact@v3
with:
path: ${{ github.workspace }}/drop/*
name: drop
- name: Upload Release
if: startsWith(github.ref, 'refs/tags/')
uses: ncipollo/release-action@v1
with:
artifacts: >
${{ github.workspace }}/drop/main.bicep,
${{ github.workspace }}/drop/main.json
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
allowUpdates: true