-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (133 loc) · 4.17 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
name: CI
on:
push:
paths:
- '**'
branches:
- '**'
tags:
- '*.*.*'
workflow_dispatch:
env:
ARTIFACT_NAME: Matrix-Bot
DOCKER_IMAGE_NAME: matrix-bot
DOCKER_REGISTRY_DOMAIN: ghcr.io
jobs:
build:
name: Build
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Lint
run: npx eslint
- name: Build
run: npx tsc
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: |
dist/
package.json
package-lock.json
example.env
docker:
name: Docker
runs-on: ubuntu-22.04
needs: build
permissions:
contents: read
packages: write
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
uses: docker/#-action@v3
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@v5
with:
images: ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}
flavor: latest=${{ github.ref_name == 'main' }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
labels: |
org.opencontainers.image.title=Matrix Bot
org.opencontainers.image.vendor=${{ github.repository_owner }}
com.docker.extension.publisher-url=https://viral32111.com
- name: Build & push Docker image
uses: docker/build-push-action@v6
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/' ) }}
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@v4
- 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@v2
with:
draft: true
tag_name: ${{ github.ref_name }}
files: ${{ env.ARTIFACT_NAME }}.zip
token: ${{ secrets.GITHUB_TOKEN }}