Skip to content

Commit

Permalink
ci(GH-actions): fix print-matrix action
Browse files Browse the repository at this point in the history
  • Loading branch information
monyarm committed Apr 19, 2024
1 parent b81bf09 commit db701d2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
12 changes: 5 additions & 7 deletions .github/print-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ inputs:
substituters:
description: Substituters
required: true
comment_matrix:
description: Whether to post a comment/upload the matrix
required: false
default: true
precalc_matrix:
description: Pre-calculated matrix
required: true
token:
description: GitHub token
required: true

outputs:
matrix:
Expand Down Expand Up @@ -62,22 +61,21 @@ runs:
PRECALC_MATRIX: ${{ inputs.precalc_matrix }}
run: |
nix run github:metacraft-labs/nixos-modules/feat/CD#mcl print_table
cat comment.md
# echo "comment<<$EOF" >> $GITHUB_OUTPUT
# cat comment.md >> $GITHUB_OUTPUT
# echo $EOF >> $GITHUB_OUTPUT
# cat $GITHUB_OUTPUT
- name: Upload CI Matrix
if: ${{ inputs.comment_matrix == true }}
uses: actions/upload-artifact@v4
with:
name: matrix-${{ inputs.is-initial == 'true' && 'pre' || 'post' }}.json
path: matrix-${{ inputs.is-initial == 'true' && 'pre' || 'post' }}.json

- name: Update GitHub Comment
if: ${{ inputs.comment_matrix == true }}
uses: marocchino/[email protected]
with:
GITHUB_TOKEN: ${{ inputs.token }}
recreate: true
path: comment.md
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ jobs:
name: Merge Matrix
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
fullMatrix: ${{ steps.matrix.outputs.fullMatrix }}
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- run: |
ls */matrix-pre.json
cat */matrix-pre.json
matrix="$(cat */matrix-pre.json | jq -cr '.include' | jq -s 'add' | jq -c '. | {include: .}')"
matrix="$(cat */matrix-pre.json | jq -cr '.include.[]' | jq '[ select (.isCached == false) ]' | jq -s 'add' | jq '. | {include: .}'
fullMatrix="$(cat */matrix-pre.json | jq -cr '.include' | jq -s 'add' | jq -c '. | {include: .}')"
echo $matrix
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "fullMatrix=$fullMatrix" >> $GITHUB_OUTPUT
id: matrix
- name: Post Comment
id: print-matrix
Expand All @@ -112,14 +115,15 @@ jobs:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
substituters: ${{ vars.SUBSTITUTERS }}
precalc_matrix: ${{ steps.matrix.outputs.matrix }}
precalc_matrix: ${{ steps.matrix.outputs.fullMatrix }}
token: ${{ secrets.GITHUB_TOKEN }}
build:
needs: slurp-matrix
if: needs.slurp-matrix.outputs.matrix != '' && needs.slurp-matrix.outputs.matrix != '{}' && needs.slurp-matrix.outputs.matrix != '{"include":[]}'
if: needs.slurp-matrix.outputs.matrix != '' && needs.slurp-matrix.outputs.matrix != '{}' && needs.slurp-matrix.outputs.matrix != '{"include":[] }'

strategy:
fail-fast: false
matrix: ${{fromJSON( needs.slurp-matrix.outputs.matrix )}}
matrix: ${{fromJSON( needs.slurp-matrix.outputs.matrix )}}

name: ${{ matrix.name }} | ${{ matrix.system }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -159,7 +163,8 @@ jobs:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
substituters: ${{ vars.SUBSTITUTERS }}
precalc_matrix: ${{ needs.slurp-matrix.outputs.matrix }}
precalc_matrix: ${{ needs.slurp-matrix.outputs.fullMatrix }}
token: ${{ secrets.GITHUB_TOKEN }}

- uses: cachix/cachix-action@v14
if: ${{inputs.do_deploy == 'true' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) }}
Expand Down
1 change: 0 additions & 1 deletion packages/mcl/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ targetPath "build"
dflags "-preview=shortenedMethods"
dflags "-defaultlib=libphobos2.so" platform="dmd"
lflags "-fuse-ld=gold" platform="dmd"
libs "curl"
1 change: 1 addition & 0 deletions packages/mcl/src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int main(string[] args)

writeln("Running ", __traits(identifier, cmd));
cmd();
writeln("Execution Succesfull");
return 0;

}
Expand Down
13 changes: 5 additions & 8 deletions packages/mcl/src/src/mcl/commands/ci_matrix.d
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ unittest

void saveCachixDeploySpec(Package[] packages)
{
auto agents = packages.map!(pkg => JSONValue([
auto agents = packages.filter!(pkg => pkg.isCached == false).map!(pkg => JSONValue([
"package": pkg.name,
"out": pkg.output
])).array;
Expand All @@ -351,17 +351,14 @@ unittest
createResultDirs();
saveCachixDeploySpec(cast(Package[]) testPackageArray);
JSONValue deploySpec = parseJSON((resultDir() ~ "/cachix-deploy-spec.json").readText);
assert(testPackageArray[0].name == deploySpec[0]["package"].str);
assert(testPackageArray[0].output == deploySpec[0]["out"].str);
assert(testPackageArray[1].name == deploySpec[1]["package"].str);
assert(testPackageArray[1].output == deploySpec[1]["out"].str);
assert(testPackageArray[1].name == deploySpec[0]["package"].str);
assert(testPackageArray[1].output == deploySpec[0]["out"].str);
}

void saveGHCIMatrix(Package[] packages)
{
auto packagesToBuild = packages.filter!(pkg => !pkg.isCached).array;
auto matrix = JSONValue([
"include": JSONValue(packagesToBuild.map!(pkg => pkg.toJSON()).array)
"include": JSONValue(packages.map!(pkg => pkg.toJSON()).array)
]);
string resPath = rootDir() ~ (params.isInitial ? "matrix-pre.json" : "matrix-post.json");
resPath.write(JSONValue(matrix).toString(JSONOptions.doNotEscapeSlashes));
Expand All @@ -376,7 +373,7 @@ unittest
saveGHCIMatrix(cast(Package[]) testPackageArray);
JSONValue matrix = parseJSON((rootDir() ~ (params.isInitial ? "matrix-pre.json"
: "matrix-post.json")).readText);
assert(testPackageArray[1].name == matrix["include"][0]["name"].str); //testPackageArray[1] is not cached, so it should be in the matrix
assert(testPackageArray[0].name == matrix["include"][0]["name"].str);
}

void saveGHCIComment(SummaryTableEntry[] tableSummaryJSON)
Expand Down

0 comments on commit db701d2

Please sign in to comment.