mirror of
https://github.com/samschott/maestral.git
synced 2024-10-06 02:18:08 +03:00
136 lines
4.9 KiB
YAML
136 lines
4.9 KiB
YAML
name: Publish to PyPI and Docker
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*.*.*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
pypi:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-python@v4.5.0
|
|
with:
|
|
python-version: '3.x'
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install build twine
|
|
|
|
- name: Build and publish
|
|
env:
|
|
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
|
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
|
run: |
|
|
python -m build
|
|
twine upload --skip-existing dist/*
|
|
|
|
docker-hub:
|
|
runs-on: ubuntu-latest
|
|
needs: pypi
|
|
steps:
|
|
- name: Checkout project
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Fetching tags
|
|
run: git fetch --prune --unshallow --force --tags
|
|
|
|
- name: Prepare
|
|
id: prep
|
|
run: |
|
|
DOCKER_IMAGE=maestraldbx/maestral
|
|
LAST_GIT_TAG=$(git describe --tags --abbrev=0)
|
|
MAESTRAL_VERSION=${LAST_GIT_TAG:1}
|
|
VERSION=noop
|
|
GIT_BRANCH=${GITHUB_REF##*/}
|
|
if [ "${{ github.event_name }}" = "schedule" ]; then
|
|
VERSION=nightly
|
|
elif [ "${{ github.event_name }}" = "pull_request_target" ]; then
|
|
VERSION=pr-${{ github.event.number }}
|
|
elif [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
|
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
|
|
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
|
|
VERSION=edge
|
|
fi
|
|
fi
|
|
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
|
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
|
MAESTRAL_VERSION=${VERSION:1}
|
|
MINOR=${MAESTRAL_VERSION%.*}
|
|
MAJOR=${MINOR%.*}
|
|
TAGS="${DOCKER_IMAGE}:${MAESTRAL_VERSION},${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
|
|
fi
|
|
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "maestral_version=${MAESTRAL_VERSION}" >> $GITHUB_OUTPUT
|
|
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
|
|
echo "git_branch=${GIT_BRANCH}" >> $GITHUB_OUTPUT
|
|
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
|
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for PyPI release
|
|
run: |
|
|
while [[ $(curl -s "https://pypi.org/pypi/maestral/$MAESTRAL_VERSION/json") == *"Not Found"* ]]
|
|
do
|
|
sleep 2
|
|
done
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
build-args: |
|
|
VERSION=${{ steps.prep.outputs.maestral_version }}
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
|
context: .
|
|
file: ./Dockerfile
|
|
# See https://github.com/opencontainers/image-spec/blob/master/annotations.md
|
|
labels: |
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
org.opencontainers.image.docker.cmd=docker run -d --rm --name maestral -v /home/dropbox:/dropbox maestral
|
|
org.opencontainers.image.documentation=https://maestral.readthedocs.io/en/latest
|
|
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
|
|
org.opencontainers.image.ref.name=${{ steps.prep.outputs.git_branch }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
|
|
org.opencontainers.image.title=Maestral
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.prep.outputs.tags }}
|
|
- name: Move cache
|
|
# Temp fix
|
|
# https://github.com/docker/build-push-action/issues/252
|
|
# https://github.com/moby/buildkit/issues/1896
|
|
if: ${{ always() }}
|
|
run: |
|
|
rm -rf /tmp/.buildx-cache
|
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|