mihomo/.github/workflows/docker.yml

81 lines
2.2 KiB
YAML
Raw Normal View History

2020-06-04 10:38:30 +08:00
name: Publish Docker Image
on:
push:
branches:
- dev
tags:
- '*'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
2022-03-06 21:48:25 +08:00
uses: actions/checkout@v3
2020-06-04 10:57:43 +08:00
with:
fetch-depth: 0
2020-06-04 10:38:30 +08:00
2020-10-17 13:46:05 +08:00
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
2020-06-04 10:38:30 +08:00
- name: Set up docker buildx
id: buildx
2020-10-17 13:46:05 +08:00
uses: docker/setup-buildx-action@v1
with:
version: latest
- name: Login to DockerHub
uses: docker/login-action@v1
2020-06-04 10:38:30 +08:00
with:
2020-10-17 13:46:05 +08:00
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to Github Package
uses: docker/login-action@v1
with:
registry: ghcr.io
username: Dreamacro
password: ${{ secrets.PACKAGE_TOKEN }}
2020-10-17 13:46:05 +08:00
- name: Build dev branch and push
2020-06-04 10:38:30 +08:00
if: github.ref == 'refs/heads/dev'
2020-10-17 13:46:05 +08:00
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
2020-10-17 13:46:05 +08:00
push: true
tags: 'dreamacro/clash:dev,ghcr.io/dreamacro/clash:dev'
2022-04-14 23:37:41 +08:00
cache-from: type=gha
cache-to: type=gha,mode=max
2020-06-04 10:38:30 +08:00
2020-10-17 13:46:05 +08:00
- name: Get all docker tags
2020-06-04 10:38:30 +08:00
if: startsWith(github.ref, 'refs/tags/')
2022-03-06 21:48:25 +08:00
uses: actions/github-script@v6
2020-10-17 13:46:05 +08:00
id: tags
2020-06-04 10:38:30 +08:00
with:
script: |
2022-03-16 12:10:13 +08:00
const ref = context.payload.ref.replace(/\/?refs\/tags\//, '')
2020-10-17 13:46:05 +08:00
const tags = [
'dreamacro/clash:latest',
`dreamacro/clash:${ref}`,
'ghcr.io/dreamacro/clash:latest',
`ghcr.io/dreamacro/clash:${ref}`
2020-10-17 13:46:05 +08:00
]
return tags.join(',')
2020-06-04 10:38:30 +08:00
result-encoding: string
2020-10-17 13:46:05 +08:00
- name: Build release and push
2020-06-04 10:38:30 +08:00
if: startsWith(github.ref, 'refs/tags/')
2020-10-17 13:46:05 +08:00
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
2020-10-17 13:46:05 +08:00
push: true
tags: ${{steps.tags.outputs.result}}
2022-04-14 23:37:41 +08:00
cache-from: type=gha
cache-to: type=gha,mode=max