86 lines
No EOL
2.7 KiB
YAML
86 lines
No EOL
2.7 KiB
YAML
name: ytld-sub Docker Build
|
|
|
|
on:
|
|
push:
|
|
# Publish `master` as Docker `latest` image.
|
|
branches:
|
|
- master
|
|
|
|
# Publish `v1.2.3` tags as releases.
|
|
tags:
|
|
- v*
|
|
|
|
# Run tests for any PRs.
|
|
pull_request:
|
|
|
|
env:
|
|
IMAGE_NAME: ytdl-sub
|
|
|
|
jobs:
|
|
# Push image to GitHub Packages.
|
|
# See also https://docs.docker.com/docker-hub/builds/
|
|
push:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
python-version: [ "3.10" ]
|
|
|
|
permissions:
|
|
packages: write
|
|
contents: read
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v3
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Build Wheel
|
|
run: |
|
|
pip install -e .[build]
|
|
python setup.py bdist_wheel
|
|
cp dist/*.whl docker/root
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
with:
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
- name: Docker Setup Buildx
|
|
uses: docker/setup-buildx-action@v2.0.0
|
|
|
|
- name: Build Docker Image
|
|
run: docker buildx build --platform=linux/amd64,linux/arm64 --cache-to=type=local,dest=/tmp/build-cache --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" docker/
|
|
|
|
- name: login to GitHub Container Registry
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build preparations
|
|
if: ${{ github.ref }} =~ ^refs\/heads\/master|^refs\/tags\/v.*
|
|
id: preperations
|
|
run: |
|
|
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
|
|
|
|
# Change all uppercase to lowercase
|
|
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
|
|
# 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" == "master" ] && VERSION=latest
|
|
echo IMAGE_ID=$IMAGE_ID
|
|
echo VERSION=$VERSION
|
|
echo "::set-output name=IMAGE_TAG::$(
|
|
echo $IMAGE_ID:$VERSION
|
|
)"
|
|
|
|
- name: Build Docker Image and push to registry
|
|
if: ${{ github.ref }} =~ ^refs\/heads\/master|^refs\/tags\/v.*
|
|
run: docker buildx build --push --platform=linux/amd64,linux/arm64 --cache-from=type=local,src=/tmp/build-cache --tag ${{ steps.preperations.outputs.IMAGE_TAG }} --label "runnumber=${GITHUB_RUN_ID}" docker/ |