Build & Publish #938
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Publish | |
on: | |
schedule: | |
- cron: '0 10 * * *' # everyday at 10am | |
push: | |
branches: | |
- '**' | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
jobs: | |
build_and_publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Git credentials | |
uses: oleksiyrudenko/[email protected] | |
with: | |
token: '${{ secrets.GITHUB_TOKEN }}' | |
- name: Synchronize README and current versions | |
run: | | |
DOCKER_IMAGE=${{ github.repository }} | |
docker build . -t ${DOCKER_IMAGE} | |
docker run --rm -v ${PWD}:/opt/generated ${DOCKER_IMAGE} node generate-versions.js | |
- name: Commit results, if any | |
run: | | |
git commit README.md current-versions.json -m 'Re-build README.md and versions' || echo "No changes to commit" | |
git push origin || echo "No changes to commit" | |
- name: Prepare Docker Image Tags | |
id: prep | |
run: | | |
DOCKER_IMAGE=${{ github.repository }} | |
VERSION=noop | |
if [ "${{ github.event_name }}" = "schedule" ]; then | |
VERSION=nightly | |
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 | |
elif [[ $GITHUB_REF == refs/pull/* ]]; then | |
VERSION=pr-${{ github.event.number }} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
MINOR=${VERSION%.*} | |
MAJOR=${MINOR%.*} | |
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" | |
fi | |
echo ::set-output name=version::${VERSION} | |
echo ::set-output name=tags::${TAGS} | |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64,linux/386 | |
target: tools | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prep.outputs.tags }} | |
labels: | | |
org.opencontainers.image.title=${{ github.event.repository.name }} | |
org.opencontainers.image.description=${{ github.event.repository.description }} | |
org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
- name: Docker Hub Description | |
if: github.ref == 'refs/heads/master' | |
uses: peter-evans/[email protected] | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DOCKERHUB_REPOSITORY: ${{ github.repository }} |