Skip to content
name: Create Docker image and publish to GH Packages
on:
push:
branches: [ main, 20-create-empty-commit-on-scheduled-upgrade-of-containers ] # create a new version whenever we push to main
schedule:
- cron: "12 2 2 * *" # run at 2:12 of the 2nd of every month
env:
DOCKER_REGISTRY: ghcr.io # where to register the image
REPO_PATH: github.com/furrer-lab/abn.git
# REPO_PATH: github.com:furrer-lab/abn.git # for private repo cloned via ssh
# Set the path to the package where the DESCRIPTION file can be found
PACKAGE_PATH: ${{ vars.PACKAGE_PATH || './' }}
JAGS: JAGS-4.3.2
GIT_CHGLOG_VERSION: git-chglog_0.15.4_linux_amd64
CHANGELOG_RELEASE: https://github.com/git-chglog/git-chglog/releases/download/v0.15.4/{{ env.GIT_CHGLOG_VERSION }}.tar.gz
jobs:
increment-and-publish-tag:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
VERSION: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Auto increment calver version
uses: reecetech/[email protected]
id: version
with:
scheme: calver
- name: Get git-chglog and update CHANGELOG
run: |
wget ${{ env.CHANGELOG_RELEASE }} # get the binary for the chglog
tar --extract --file=${{ env.CHANGELOG_RELEASE}}.tar.gz git-chglog
git tag -a ${{ steps.version.outputs.version }} -m 'interim tag for changelog'
./git-chglog -o CHANGELOG.md # update the changelog file
git tag -d ${{ steps.version.outputs.version }} # remove the tag again
- name: Commit CHANGELOG.md update
uses: EndBug/add-and-commit@v9
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
default_author: github_actions
message: "auto-update: CHANGELOG.md"
add: 'CHANGELOG.md'
tag: '${{ steps.version.outputs.version }}'
build-and-push:
runs-on: ubuntu-latest
needs: increment-and-publish-tag
env:
CUSTOM_TAG: "${{ needs.increment-and-publish-tag.outputs.VERSION }}"
permissions: # for `GITHUB_TOKEN`
contents: read
packages: write
strategy:
fail-fast: false
matrix:
target-os: ['debian', 'fedora']
compiler: ['gcc', 'clang']
r-version: ['devel', 'release', 'patched']
exclude:
- target-os: 'fedora'
r-version: 'release'
- target-os: 'fedora'
r-version: 'patched'
- compiler: 'clang'
r-version: 'patched'
- compiler: 'clang'
r-version: 'release'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tags and labels
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
# TODO: set a proper name of the image (same as in context below)
images: ${{ env.DOCKER_REGISTRY}}/${{ format('{0}/{1}/{2}/{3}/abn', github.repository, matrix.target-os, matrix.compiler, matrix.r-version ) }}
tags: | # set Docker tags to git tags
type=raw,value=${{ env.CUSTOM_TAG }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
#type=semver,pattern={{version}}
# For private repo cloned via ssh we need a deploy key
# - name: Write the ssh key file
# run: |
# echo "${{ secrets.DEVEL_ABN_DEPLOY }}" >> ssh_key
# shell: bash
- name: Build and push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ${{ format('./containers/{0}/', matrix.target-os ) }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TARGET_OS=${{ matrix.target-os }}
COMPILER=${{ matrix.compiler }}
R_VERSION=${{ matrix.r-version }}
PACKAGE_PATH=${{ env.PACKAGE_PATH}}
REPO_PATH=${{ env.REPO_PATH }}
JAGS=${{ env.JAGS}}
# For private repo cloned via ssh
# secret-files: |
# key=./ssh_key