76 lines
2.1 KiB
YAML
76 lines
2.1 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: Build Docker Image
|
|
run: docker build --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: Push image on master or release
|
|
run: |
|
|
if [[ ${{ github.ref }} =~ ^refs\/heads\/master|^refs\/tags\/v.* ]]; then
|
|
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
|
|
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
|
|
docker push $IMAGE_ID:$VERSION
|
|
else
|
|
echo "Skipped on PRs"
|
|
fi
|
|
|