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: Build image
run: docker build . --file Dockerfile --tag ${{ github.event.repository.name }} --label "runnumber=${GITHUB_RUN_ID}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1 - name: Authenticate with ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 - name: Push image
run: |
- name: Log in to Docker Hub # Destiination, trsnform to lowercase
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]')
with: function tag_push() {
username: ${{ secrets.DOCKER_USER }} docker tag ${{ github.event.repository.name }} $IMAGE_ID:$1
password: ${{ secrets.DOCKER_PASSWORD }} docker push $IMAGE_ID:$1
}
- name: Log in to the Container registry # Strip git ref prefix from version
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
with: # trigger is (hopefully semantically) tagged
registry: ghcr.io if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
username: ${{ github.actor }} # Strip +buildinfo
password: ${{ secrets.GITHUB_TOKEN }} VERSION=$(cut -d+ -f1 <<< $VERSION)
# Strip "v" prefix from tag name (v1.2.3 to 1.2.3)
- name: 'Get Previous tag' VERSION=$(sed -e 's/^v//' <<< $VERSION)
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1" if [[ -z $(cut -sd- -f1 <<< $VERSION) ]]; then # Not a prerelease (not v0.1.2-rc4)
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" [[ ${TAG_LATEST} == "true" ]] && tag_push latest
- name: Build image and push to Docker Hub and GitHub Container Registry tag_push $VERSION # push patch (:1.2.3)
uses: docker/build-push-action@v3
with: # push minor version (:1.2)
context: . VERSION=$(cut -d. -f -2 <<< $VERSION)
tags: | tag_push $VERSION
supernova3339/anonupload:latest
supernova3339/anonupload:${{ steps.previoustag.outputs.tag }} # major version (:1)
ghcr.io/supernova3339/anonupload:latest VERSION=$(cut -d. -f -1 <<< $VERSION)
ghcr.io/supernova3339/anonupload:${{ steps.previoustag.outputs.tag }} fi
# build on feature branches, push only on main branch fi
push: ${{ github.ref == 'refs/heads/master' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7 # 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