2024-03-13 01:30:45 -04:00
|
|
|
name: Build and Push Docker
|
2023-09-13 03:26:56 -04:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2023-09-14 12:31:57 -04:00
|
|
|
branches:
|
|
|
|
- dev
|
2023-09-14 21:59:21 -04:00
|
|
|
tags:
|
2024-03-13 01:30:45 -04:00
|
|
|
- "*"
|
2023-09-14 05:59:17 -04:00
|
|
|
workflow_dispatch:
|
2023-09-13 03:26:56 -04:00
|
|
|
|
|
|
|
jobs:
|
2024-03-13 01:30:45 -04:00
|
|
|
build-and-push:
|
2023-09-13 03:26:56 -04:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2023-09-14 21:59:21 -04:00
|
|
|
- name: Check out code
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
2024-03-13 01:30:45 -04:00
|
|
|
uses: docker/login-action@v3
|
2023-09-14 21:59:21 -04:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2024-03-13 01:30:45 -04:00
|
|
|
- name: Login to Docker Hub
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
2023-09-14 21:59:21 -04:00
|
|
|
|
2024-03-13 01:30:45 -04:00
|
|
|
- name: Docker meta
|
|
|
|
id: meta
|
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
with:
|
|
|
|
images: |
|
|
|
|
${{ secrets.DOCKER_HUB_USERNAME }}/sub2clash
|
|
|
|
ghcr.io/${{ github.repository }}
|
|
|
|
|
|
|
|
- name: Prepare args
|
|
|
|
id: prep
|
2023-09-14 21:59:21 -04:00
|
|
|
run: |
|
2024-03-13 01:30:45 -04:00
|
|
|
if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
|
|
|
|
VERSION="${{ github.sha }}"
|
|
|
|
fi
|
|
|
|
if [[ "$GITHUB_REF" == 'refs/heads/dev' ]]; then
|
|
|
|
VERSION="${{ github.sha }}"
|
|
|
|
fi
|
|
|
|
if [[ "$GITHUB_REF" == 'refs/tags/'* ]]; then
|
|
|
|
VERSION=$TAG_NAME
|
2023-09-14 21:59:21 -04:00
|
|
|
fi
|
2024-03-13 01:30:45 -04:00
|
|
|
echo "version=$VERSION" >> $GITHUB_ENV
|
2023-09-14 21:59:21 -04:00
|
|
|
|
|
|
|
|
2024-03-13 01:30:45 -04:00
|
|
|
- name: Set up Docker buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
|
|
|
- name: Build and push Docker image to GHCR and Docker Hub
|
|
|
|
uses: docker/build-push-action@v5
|
2023-09-14 21:59:21 -04:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
2024-03-13 01:30:45 -04:00
|
|
|
build-args: version=${{ env.version }}
|
2023-09-14 21:59:21 -04:00
|
|
|
push: true
|
2024-03-13 01:30:45 -04:00
|
|
|
platforms: linux/amd64,linux/arm,linux/arm64
|
|
|
|
tags: ${{ steps.prep.outputs.tags }}
|