forked from hznuoj-dev/hznuoj
-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (120 loc) · 4.36 KB
/
release.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
# yaml-language-server: $schema=https://json-schema.org/draft-07/schema#
name: Release
on:
push:
branches:
- master
workflow_dispatch:
jobs:
release_github_packages:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.check_version.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Check Version
id: check_version
shell: bash
run: |
if [[ -f VERSION ]]; then
version=$(cat VERSION)
tags=$(git tag --list)
echo $tags
if [[ ! "$tags" =~ (^|[[:space:]])"$version"($|[[:space:]]) ]]; then
echo $version
echo "::set-output name=tag::$version"
fi
fi
- name: Create Tag
if: ${{ startsWith(steps.check_version.outputs.tag, 'v') }}
run: |
git tag ${{ steps.check_version.outputs.tag }}
git push origin ${{ steps.check_version.outputs.tag }}
- name: Release
if: ${{ startsWith(steps.check_version.outputs.tag, 'v') }}
run: npx changelogithub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release-docker-image:
runs-on: ubuntu-latest
needs: release_github_packages
if: ${{ startsWith(needs.release_github_packages.outputs.tag, 'v') }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Tag
id: get-tag
run: |
tag=$(cat VERSION)
echo "before: ${tag}"
prefix="v"
tag=${tag#"${prefix}"}
echo "::set-output name=tag::$(echo $tag)"
echo "after: ${tag}"
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Inspect builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to ALiYun Container Registry
uses: docker/login-action@v3
with:
registry: registry.cn-beijing.aliyuncs.com
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
password: ${{ secrets.ALIYUN_REGISTRY_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Build and push
uses: docker/build-push-action@v5
env:
image_name: hznuoj
tag: ${{ steps.get-tag.outputs.tag }}
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
hznuoj/${{ env.image_name }}:latest
hznuoj/${{ env.image_name }}:${{ env.tag }}
registry.cn-beijing.aliyuncs.com/dup4/${{ env.image_name }}:latest
registry.cn-beijing.aliyuncs.com/dup4/${{ env.image_name }}:${{ env.tag }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache