Skip to content

Commit

Permalink
update workflow to use matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
mircea-pavel-anton committed Aug 28, 2024
1 parent 20efb4f commit c5fb923
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
14 changes: 10 additions & 4 deletions .github/scripts/generate_matrix.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import path from 'path'
import { Octokit } from '@octokit/rest'

// Configuration from environment variables
const GITHUB_OWNER = process.env.GITHUB_OWNER;
const GITHUB_OWNER = process.env.GITHUB_REPOSITORY.split('/')[0];
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

const octokit = new Octokit({ auth: GITHUB_TOKEN });
Expand Down Expand Up @@ -83,8 +83,9 @@ async function generateMatrix() {
console.log(`Image ${image_name}:${version} already exists. Skipping build.`);
} else {
matrix.push({
name: image_name,
path: folderPath,
image_name: `ghcr.io/${GITHUB_OWNER}/${image_name}`,
context: folderPath,
dockerfile: dockerfilePath,
version: version
});
}
Expand All @@ -95,7 +96,12 @@ async function generateMatrix() {
}
}

console.log(JSON.stringify({ include: matrix }, null, 2));
fs.writeFile("./matrix.json", JSON.stringify({ include: matrix }, null, 2), function (err) {
if (err) {
return console.log(err);
}
console.log("matrix.json file was saved!");
});
}

generateMatrix().catch(error => {
Expand Down
43 changes: 35 additions & 8 deletions .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Docker Release: Taskfile"
name: "Docker: Build and Push"

on:
push:
paths:
- 'containers/**'
pull_request:
branches: ["main"]
paths:
- "containers/taskfile/**/*"
- 'containers/**'

jobs:
release:
generate-matrix:
runs-on: ubuntu-latest
container: mcr.microsoft.com/devcontainers/javascript-node:22-bookworm
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
env:
GITHUB_OWNER: ${{ secrets.GHCR_REPO }} # GHCR repo name
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: npm install

- name: Generate matrix
id: generate-matrix
run: |
npm run generate-matrix
echo "::set-output name=matrix::$(cat matrix.json)"
build:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
uses: mirceanton/reusable-workflows/.github/workflows/docker-release.yaml@main
secrets: inherit
with:
image-name: ghcr.io/mirceanton/taskfile
image-name: ${{ matrix.image_name }}
platforms: linux/amd64, linux/arm64
custom-tag: "testing"
context: containers/taskfile
dockerfile: containers/taskfile/Dockerfile
custom-tag: ${{ matrix.version }}
context: ${{ matrix.context }}
dockerfile: ${{ matrix.dockerfile }}

0 comments on commit c5fb923

Please sign in to comment.