Skip to content

Add badge

Add badge #95

name: Docker
concurrency:
group: docker-${{ github.head_ref }}
cancel-in-progress: true
on:
workflow_dispatch: # Allow manual triggers
inputs:
tags:
description: 'Tags'
required: false
push:
# Publish `main` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
env:
# Change variable to your image's name.
IMAGE_NAME: send-message-to-wechat
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
if: github.event.repository.owner.login == 'HollowMan6'
steps:
- name: Checkout
uses: actions/checkout@main
- name: Set up QEMU
uses: docker/setup-qemu-action@master
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into GitHub Container Registry
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.actor }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
if [ -z "${{ github.event.inputs.tags }}" ]
then
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
else
VERSION=${{ github.event.inputs.tags }}
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Log into Docker Hub
run: echo ${{ secrets.DOCKERHUB_PW }} | docker login -u ${{ secrets.DOCKERHUB_UN }} --password-stdin
- name: Build Mutiple-Platform Image and Push to Docker Hub
run: |
IMAGE_ID=${{ secrets.DOCKERHUB_UN }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
if [ -z "${{ github.event.inputs.tags }}" ]
then
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
else
VERSION=${{ github.event.inputs.tags }}
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker buildx build -t $IMAGE_ID:$VERSION --platform linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6,linux/mips64le --push .