-
Notifications
You must be signed in to change notification settings - Fork 4
124 lines (108 loc) · 3.62 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
name: Docker Image CI
on:
push:
branches: ["release", "main"]
pull_request:
branches: ["main"]
jobs:
setup-and-cache:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache-node-modules.outputs.cache-hit }}
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-
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm install
- name: Copy node_modules to project directory (if not present)
run: |
if [ ! -d "node_modules" ]; then
cp -r node_modules ./
fi
tag:
runs-on: ubuntu-latest
needs: setup-and-cache
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: [tag]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: check value
run: |
echo "need_create "${{ needs.tag.outputs.need_create }}
echo "latest_tag1 "${{ needs.tag.outputs.latest_tag }}
- name: push tag
if: needs.tag.outputs.need_create == 'true'
env:
latest_tag: ${{ needs.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: [tag, create-tag]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- 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.tag.outputs.latest_tag }}
- name: Build and push latest
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: smile0301/auto-pixai:latest