Update Container (latest) #1379
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: Update Container (latest) | |
on: | |
schedule: | |
- cron: '10 0 * * *' # Every Day | |
workflow_dispatch: | |
inputs: | |
force_deploy: | |
description: 'Force a container build, even if no changes' | |
required: true | |
default: 'false' | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'Dockerfile.*' | |
- '.github/workflows/**' | |
jobs: | |
check-upstream: | |
name: Check for new upstream revision | |
runs-on: ubuntu-latest | |
outputs: | |
modified: ${{ steps.git-check.outputs.modified }} | |
upstream-tag: ${{ steps.upstream-tag.outputs.upstream-tag }} | |
upstream-major: ${{ steps.upstream-tag.outputs.upstream-major }} | |
upstream-minor: ${{ steps.upstream-tag.outputs.upstream-minor }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Fetch release version | |
run: | | |
git fetch | |
# Get releases | |
curl -sL 'https://api.github.com/repos/apache/superset/releases' > /tmp/releases_temp.json | |
# Extract latest tag of 1.x.x (exclude release candidates) | |
tagName=$(jq -r '[ .[] | select( .tag_name | test("^1\\.[0-9]+\\.[0-9]+$") ) ] | max_by( .tag_name | split(".") | map(tonumber) ) | .tag_name' /tmp/releases_temp.json) | |
# Store superset-latest.json | |
jq --arg tagName "$tagName" -r ".[] | select( .tag_name == \"$tagName\" ) | del(.reactions)" /tmp/releases_temp.json > superset-latest.json | |
- name: Check for modified files | |
id: git-check | |
run: echo ::set-output name=modified::$([ -z "`git status --porcelain`" ] && echo "unchanged" || echo "true") | |
- name: Store upstream tag | |
id: upstream-tag | |
run: | | |
upstreamTag=$(jq -r '.tag_name' superset-latest.json) | |
echo ::set-output name=upstream-tag::${upstreamTag} | |
echo ::set-output name=upstream-major::${upstreamTag%%.*} | |
echo ::set-output name=upstream-minor::${upstreamTag%.*} | |
- name: Commit latest upstream revision | |
if: steps.git-check.outputs.modified == 'true' | |
run: | | |
git config --global user.name '${{ github.actor }}' | |
git config --global user.email '${{ github.actor }}@users.noreply.github.com' | |
git commit -am "New upstream revision" | |
git push | |
publish-image: | |
name: Publish to ghcr.io | |
needs: check-upstream | |
if: | | |
needs.check-upstream.outputs.modified == 'true' || | |
( github.event_name == 'push' ) || | |
( github.event_name == 'workflow_dispatch' && github.event.inputs.force_deploy != 'false' ) | |
strategy: | |
matrix: | |
DOCKER_IMAGE: [superset-oauth] # Array: [superset,superset-oauth] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use upstream tag (${{ needs.check-upstream.outputs.upstream-tag }}) in Dockerfile | |
run: | | |
sed -i'' "s/FROM apache\/superset AS/FROM apache\/superset:${{ needs.check-upstream.outputs.upstream-tag }} AS/" Dockerfile.${{ matrix.DOCKER_IMAGE }} | |
- name: Publish to GitHub Registry | |
uses: elgohr/Publish-Docker-Github-Action@v5 | |
with: | |
name: ghcr.io/${{ github.repository_owner }}/${{ matrix.DOCKER_IMAGE }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ghcr.io | |
dockerfile: Dockerfile.${{ matrix.DOCKER_IMAGE }} | |
tags: "latest,stable,v${{ needs.check-upstream.outputs.upstream-tag }},v${{ needs.check-upstream.outputs.upstream-major }},v${{ needs.check-upstream.outputs.upstream-minor }}" |