Skip to content

Commit

Permalink
Refactor using a github matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Silex committed May 10, 2024
1 parent 3c46dc2 commit 16a734a
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 2,947 deletions.
35 changes: 15 additions & 20 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
inputs:
dockerhub_username:
secrets:
required: true
dockerhub_token:
version:
required: true
emacs:
context:
required: true

runs:
using: composite
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ inputs.dockerhub_username }}
password: ${{ inputs.dockerhub_token }}
username: ${{ fromJSON(inputs.secrets).DOCKERHUB_USERNAME }}
password: ${{ fromJSON(inputs.secrets).DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Set environment
- uses: ruby/setup-ruby@v1

- name: Get data
id: data
shell: bash
run: |
yq() { docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@"; }
VERSION="${{ inputs.emacs }}"
tags=$(yq ".[] | select(.tags[0] == \"$VERSION\") | .tags | join (\", silex/emacs:\")" images.yml)
version=$(yq ".[] | select(.tags[0] == \"$VERSION\") | .version" images.yml)
cache=$(yq ".[] | select(.tags[0] == \"$VERSION\") | .tags[0]" images.yml)
template=$(yq ".[] | select(.tags[0] == \"$VERSION\") | .template" images.yml)
echo "image_tags=silex/emacs:$tags" >> $GITHUB_ENV
echo "image_cache=silex/emacs:$cache" >> $GITHUB_ENV
echo "image_context=$version/$template" >> $GITHUB_ENV
echo "tags=$(bin/images --json | jq -c '.images[] | select(.directory == "${{ inputs.version }}/${{ inputs.context }}") | .tags_with_repository')" >> $GITHUB_OUTPUT
- name: Build
- name: Build image
uses: docker/build-push-action@v5
with:
pull: true
push: ${{ github.ref == 'refs/heads/master' }}
cache-from: ${{ env.image_cache }}
cache-from: ${{ fromJSON(steps.data.outputs.tags)[0] }}
cache-to: '"type=inline"'
tags: ${{ env.image_tags }}
context: ${{ env.image_context }}
context: ${{ inputs.version }}/${{ inputs.context }}
tags: ${{ join(fromJSON(steps.data.outputs.tags), ', ') }}
62 changes: 62 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: build

on:
workflow_call:
inputs:
version:
required: true
type: string
context:
required: true
type: string

jobs:
base:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
uses: "./.github/actions/build"
with:
secrets: "${{ toJSON(secrets) }}"
version: "${{ inputs.version }}"
context: "${{ inputs.context }}"

ci:
needs: base
runs-on: ubuntu-latest
outputs:
contexts: ${{ steps.data.outputs.contexts }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
uses: "./.github/actions/build"
with:
secrets: "${{ toJSON(secrets) }}"
version: "${{ inputs.version }}"
context: "${{ inputs.context }}/ci"
- uses: ruby/setup-ruby@v1
- name: Setup variables
id: data
run: |
echo "contexts=$(bin/images --json | jq -c '.images[] | select(.directory == "${{ inputs.version }}/${{ inputs.context }}/ci") | [.children[].context]')" >> $GITHUB_OUTPUT
tools:
needs: ci
if: needs.ci.outputs.contexts != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
context: ${{ fromJSON(needs.ci.outputs.contexts) }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: build
uses: "./.github/actions/build"
with:
secrets: "${{ tojson(secrets) }}"
version: "${{ inputs.version }}"
context: "${{ matrix.context }}"
Loading

0 comments on commit 16a734a

Please sign in to comment.