Skip to content

Commit

Permalink
ci: separate build.yml and docker.yml from main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythologyli committed Sep 25, 2023
1 parent e29553b commit ca7effe
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 44 deletions.
48 changes: 4 additions & 44 deletions .github/workflows/main.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
pull_request:
types:
- opened
paths:
- "**/*.go"
- "go.mod"
- "go.sum"

permissions: write-all

Expand Down Expand Up @@ -125,47 +129,3 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ github.event.release.tag_name }} zju-connect-${{ steps.get_filename.outputs.ASSET_NAME }}.zip
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
mythologyli/zju-connect
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=raw,value=latest
# https://github.com/docker/build-push-action
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
61 changes: 61 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish Docker image

on:
release:
types: [ published ]
push:
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
- ".github/workflows/*.yml"

permissions: write-all

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout codebase
uses: actions/checkout@v3

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

# https://github.com/docker/login-action
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
mythologyli/zju-connect
tags: |
type=schedule
type=ref,event=branch
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=sha
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
# https://github.com/docker/build-push-action
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit ca7effe

Please sign in to comment.