Skip to content

Commit 1d57584

Browse files
committed
添加自动发布镜像
1 parent 3b8853b commit 1d57584

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-and-push-image:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v2
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Set up VERSION environment variable
26+
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
27+
28+
- name: Set up IMAGE_NAME environment variable
29+
run: |
30+
ORG_REPO="${{ github.repository }}"
31+
ORG=$(echo "${ORG_REPO}" | cut -d '/' -f 1 | tr '[:upper:]' '[:lower:]')
32+
REPO=$(echo "${ORG_REPO}" | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')
33+
IMAGE_NAME="ghcr.io/${ORG}/${REPO}-app"
34+
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
35+
36+
- name: Pull latest image
37+
run: docker pull ${{ env.IMAGE_NAME }}:latest
38+
39+
- name: Tag image with release version
40+
run: docker tag ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
41+
42+
- name: Push image to GitHub Container Registry
43+
run: docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}

0 commit comments

Comments
 (0)