mihomo/.github/workflows/docker.yml

77 lines
2.0 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
uses: actions/checkout@v2
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/v7,linux/arm64
push: true
tags: 'dreamacro/clash:dev,ghcr.io/dreamacro/clash:dev'
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/')
2020-08-30 23:06:21 +08:00
uses: actions/github-script@v3
2020-10-17 13:46:05 +08:00
id: tags
2020-06-04 10:38:30 +08:00
with:
script: |
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/v7,linux/arm64
push: true
tags: ${{steps.tags.outputs.result}}