-
Notifications
You must be signed in to change notification settings - Fork 3
161 lines (139 loc) · 4.71 KB
/
docker-image.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
159
160
161
name: Docker Image CI
on:
push:
branches: ["release", "main"]
pull_request:
branches: ["main"]
jobs:
setup-and-cache:
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18.17.0"
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: Install dependencies
run: npm install
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: show node version
run: node -v
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: show npm version
run: npm -v
# 上傳存儲項目
# - name: Upload node_modules
# uses: actions/upload-artifact@v3
# with:
# name: node_modules
# path: node_modules
check-tag:
runs-on: ubuntu-latest
outputs:
latest_tag: ${{ steps.latest_tag.outputs.tag }}
need_create: ${{ steps.latest_tag.outputs.need_create }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Show tags
id: latest_tag
run: |
package_version=$(node -e "console.log(require('./package.json').version)")
git fetch --tags
github_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
if [ "$package_version" != "$github_tag" ]; then
echo "need_create=true" >> "$GITHUB_OUTPUT"
latest_tag=$package_version
echo "❌ Package.json version does not match github tag"
else
echo "need_create=false" >> "$GITHUB_OUTPUT"
latest_tag=$github_tag
echo "✅ Package.json version matches github tag: $latest_tag"
fi
echo "💡 Latest tag: $latest_tag"
echo "tag=$latest_tag" >> "$GITHUB_OUTPUT"
create-tag:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
needs: [check-tag]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: check value
run: |
echo "need_create "${{ needs.check-tag.outputs.need_create }}
echo "latest_tag1 "${{ needs.check-tag.outputs.latest_tag }}
- name: push tag
if: needs.check-tag.outputs.need_create == 'true'
env:
latest_tag: ${{ needs.check-tag.outputs.latest_tag }}
run: |
# 設置身份
git config user.email "[email protected]"
git config user.name "Github Actions"
# 建立新標籤並推送到 GitHub
git tag -a "$latest_tag" -m "Release $latest_tag"
git push origin "$latest_tag"
docker-build:
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
needs: [setup-and-cache, check-tag, create-tag]
steps:
- name: Check out repository code
uses: actions/checkout@v4
# 載入存儲項目
# - name: Download node_modules
# uses: actions/download-artifact@v3
# with:
# name: node_modules
# path: node_modules
# 載入緩存
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push tag
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: smile0301/auto-pixai:${{ needs.check-tag.outputs.latest_tag }}
- name: Build and push latest
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: smile0301/auto-pixai:latest