Merge pull request #122 from rstudio/jmw/fix-build-gha #114
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: R Docker | |
on: | |
push: | |
workflow_dispatch: | |
inputs: | |
variants: | |
description: | | |
Space-separated list of variants (platforms). Defaults to all variants. | |
required: false | |
default: '' | |
type: string | |
versions: | |
description: | | |
Space-separated list of R versions. Defaults to all versions. | |
required: false | |
default: '' | |
type: string | |
publish_images: | |
description: | | |
Publish images to Docker Hub? | |
required: false | |
default: false | |
type: boolean | |
include_patch_versions: | |
description: | | |
When building all R versions, include R patch version tags (x.y.z) as well? | |
required: false | |
default: false | |
type: boolean | |
workflow_call: | |
inputs: | |
versions: | |
description: | | |
Space-separated list of R versions. Defaults to all versions. | |
required: false | |
default: '' | |
type: string | |
publish_images: | |
description: | | |
Publish images to Docker Hub? | |
required: false | |
default: false | |
type: boolean | |
include_patch_versions: | |
description: | | |
Include R patch versions? | |
required: false | |
default: false | |
type: boolean | |
secrets: | |
DOCKERHUB_USERNAME: | |
required: true | |
DOCKERHUB_TOKEN: | |
required: true | |
RSTUDIO_DOCKERHUB_USERNAME: | |
required: true | |
RSTUDIO_DOCKERHUB_TOKEN: | |
required: true | |
permissions: | |
contents: read | |
jobs: | |
setup-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.setup-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up matrix | |
id: setup-matrix | |
run: | | |
if [[ "${{ inputs.variants }}" != "" ]]; then | |
variants="${{ inputs.variants }}" | |
else | |
variants="$(make print-variants)" | |
fi | |
# Create matrix combining variants with organization repo | |
matrix=$(echo "$variants" | tr ' ' '\n' | jq -R -n ' | |
{ | |
"include": [ | |
( inputs | select(length>0) as $variant | [ | |
{ | |
variant: $variant, | |
username_secret: "DOCKERHUB_USERNAME", | |
token_secret: "DOCKERHUB_TOKEN", | |
repo: "posit/r-base" | |
}, | |
{ | |
variant: $variant, | |
username_secret: "RSTUDIO_DOCKERHUB_USERNAME", | |
token_secret: "RSTUDIO_DOCKERHUB_TOKEN", | |
repo: "rstudio/r-base" | |
} | |
] ) | |
| .[] | |
] | |
}' | jq -c .) | |
echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
docker-images: | |
needs: setup-matrix | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} | |
runs-on: ubuntu-latest | |
name: Docker images (${{ matrix.repo }}:${{ matrix.variant }}) | |
env: | |
VARIANTS: ${{ matrix.variant }} | |
BASE_IMAGE: ${{ matrix.repo }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
driver: docker | |
install: true | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets[matrix.username_secret] }} | |
password: ${{ secrets[matrix.token_secret] }} | |
- name: Setup environment | |
run: | | |
if [[ "${{ inputs.versions }}" != "" ]]; then | |
echo "VERSIONS=${{ inputs.versions }}" >> $GITHUB_ENV | |
fi | |
if [[ "${{ inputs.include_patch_versions }}" == "true" ]]; then | |
echo "INCLUDE_PATCH_VERSIONS=yes" >> $GITHUB_ENV | |
fi | |
- name: Build images | |
run: | | |
make build-all | |
- name: Test images | |
run: | | |
make test-all | |
- name: Push images | |
if: ${{ github.ref == 'refs/heads/main' || inputs.publish_images }} | |
run: | | |
make push-all |