telegram-download-daemon/.github/workflows/Docker-Publish.yml

94 lines
2.4 KiB
YAML
Raw Normal View History

2020-04-26 23:47:58 +08:00
name: Docker Publish
on:
push:
# Publish `master` as Docker `latest` image.
branches:
2020-05-19 23:38:27 +08:00
- master
2020-04-26 23:47:58 +08:00
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: telegram-download-daemon
2020-04-26 23:47:58 +08:00
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
2020-05-19 23:33:19 +08:00
pushDockerHub:
runs-on: ubuntu-latest
name: Push to Docker Hub
needs: [test]
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/telegram-download-daemon
2020-05-19 23:33:19 +08:00
tags: latest
2020-04-26 23:47:58 +08:00
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
2020-05-19 23:33:19 +08:00
pushGitHub:
name: Push to Github Registry
2020-04-26 23:47:58 +08:00
# Ensure test job passes before pushing image.
2020-05-19 23:33:19 +08:00
needs: [test]
2020-04-26 23:47:58 +08:00
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
2020-05-20 00:04:00 +08:00
run: docker build . --file Dockerfile --tag image
2020-04-26 23:47:58 +08:00
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$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
2020-04-26 23:53:48 +08:00
[ "$VERSION" == "production" ] && VERSION=latest
2020-04-26 23:47:58 +08:00
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION