pull/20/head
SuperDev 3 years ago committed by GitHub
parent d48eb3db59
commit 19afe45d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,53 +1,67 @@
name: Docker Image CI name: Release to Github Packages. # https://ghcr.io
on: # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
workflow_dispatch: workflow_dispatch:
workflow_call: push:
tags: # This builds for all branches with semantically versioned tags (v0.12.3).
- v* # https://semver.org will fail, if there are any other tags
jobs: #release: # Builds only releases. Includes draft and pre-releases.
build: #types: [created]
#pull_request: # Run 'tests' for any PRs. Default is to not run for first-time contributors: see /settings/actions
env:
TAG_LATEST: true # Encourage users to use a major version (foobar:1) instead of :latest.
# By semantic versioning standards, major changes are changes 'backwards incompatible'. Major upgrades are often rare and prehaps, need attention from the user.
jobs:
# Push image to GitHub Packages.
push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up QEMU - name: Build image
uses: docker/setup-qemu-action@v1 run: docker build . --file Dockerfile --tag ${{ github.event.repository.name }} --label "runnumber=${GITHUB_RUN_ID}"
- name: Set up Docker Buildx - name: Authenticate with ghcr.io
uses: docker/setup-buildx-action@v1 run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 'Get Previous tag' - name: Push image
id: previoustag run: |
uses: "WyriHaximus/github-action-get-previous-tag@v1" # Destiination, trsnform to lowercase
env: IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]')
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" function tag_push() {
docker tag ${{ github.event.repository.name }} $IMAGE_ID:$1
- name: Build image and push to Docker Hub and GitHub Container Registry docker push $IMAGE_ID:$1
uses: docker/build-push-action@v3 }
with: # Strip git ref prefix from version
context: . VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
tags: | # trigger is (hopefully semantically) tagged
supernova3339/anonupload:latest if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
supernova3339/anonupload:${{ steps.previoustag.outputs.tag }} # Strip +buildinfo
ghcr.io/supernova3339/anonupload:latest VERSION=$(cut -d+ -f1 <<< $VERSION)
ghcr.io/supernova3339/anonupload:${{ steps.previoustag.outputs.tag }} # Strip "v" prefix from tag name (v1.2.3 to 1.2.3)
# build on feature branches, push only on main branch VERSION=$(sed -e 's/^v//' <<< $VERSION)
push: ${{ github.ref == 'refs/heads/master' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7 if [[ -z $(cut -sd- -f1 <<< $VERSION) ]]; then # Not a prerelease (not v0.1.2-rc4)
[[ ${TAG_LATEST} == "true" ]] && tag_push latest
tag_push $VERSION # push patch (:1.2.3)
# push minor version (:1.2)
VERSION=$(cut -d. -f -2 <<< $VERSION)
tag_push $VERSION
# major version (:1)
VERSION=$(cut -d. -f -1 <<< $VERSION)
fi
fi
# push normally (and possibly major)
tag_push $VERSION
# Can't push multiple tags at once: https://github.com/docker/cli/issues/267

Loading…
Cancel
Save