-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (137 loc) · 4.65 KB
/
ci.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: CI
on:
push:
paths:
- 'Source/**/*'
- 'TwitchBot.csproj'
- 'TwitchBot.sln'
- 'Dockerfile'
- '.dockerignore'
- '.github/workflows/ci.yml'
branches:
- '**'
tags:
- '*.*.*'
workflow_dispatch:
env:
ARTIFACT_NAME: TwitchBot
DOCKER_IMAGE_NAME: twitchbot
DOCKER_REGISTRY_DOMAIN: ghcr.io
jobs:
build-test:
name: Build & Test
runs-on: ubuntu-22.04
permissions:
contents: read
packages: read
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Add GitHub Packages source
run: dotnet nuget add source --name github --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Restore dependencies
run: dotnet restore
- name: Build project
run: dotnet build --nologo --configuration Release --no-restore
- name: Run tests
run: dotnet test --nologo --configuration Release --no-build
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: bin/Release/net7.0/*
docker:
name: Docker
runs-on: ubuntu-22.04
needs: build-test
permissions:
contents: read
packages: write
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY_DOMAIN }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: artifact
- name: Create metadata for Docker image
id: metadata
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}
flavor: latest=true
tags: |
type=ref,event=branch
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
labels: |
org.opencontainers.image.title=Twitch Bot
org.opencontainers.image.description=My Twitch integration & chat bot.
com.docker.extension.publisher-url=https://viral32111.com
- name: Build & push Docker image
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
file: Dockerfile
context: artifact
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: linux/amd64
provenance: false
no-cache: true
pull: true
- name: Delete old Docker images
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
continue-on-error: true
uses: snok/container-retention-policy@v2
with:
image-names: ${{ env.DOCKER_IMAGE_NAME }}
cut-off: 24 hours ago UTC
keep-at-least: 1
untagged-only: true
skip-tags: latest
account-type: personal
token: ${{ secrets.PERSONAL_ACCESS_TOKEN_PACKAGES }}
release:
name: Release
runs-on: ubuntu-22.04
needs: docker
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
permissions:
contents: write
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: artifact
- name: Bundle build artifact
run: zip -r ${{ env.ARTIFACT_NAME }}.zip artifact
- name: Create draft release
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ github.ref_name }}
files: ${{ env.ARTIFACT_NAME }}.zip
token: ${{ secrets.GITHUB_TOKEN }}