From db701d2dd8e5228a9b5da0bd2cfcf98617efeb11 Mon Sep 17 00:00:00 2001 From: monyarm Date: Fri, 19 Apr 2024 13:34:44 +0300 Subject: [PATCH] ci(GH-actions): fix print-matrix action --- .github/print-matrix/action.yml | 12 +++++------- .github/workflows/ci.yml | 15 ++++++++++----- packages/mcl/dub.sdl | 1 - packages/mcl/src/main.d | 1 + packages/mcl/src/src/mcl/commands/ci_matrix.d | 13 +++++-------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/print-matrix/action.yml b/.github/print-matrix/action.yml index 1435c882..74b21724 100644 --- a/.github/print-matrix/action.yml +++ b/.github/print-matrix/action.yml @@ -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: @@ -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/sticky-pull-request-comment@v2.9.0 with: + GITHUB_TOKEN: ${{ inputs.token }} recreate: true path: comment.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ef8f4c2..ac1d65cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,7 @@ jobs: name: Merge Matrix outputs: matrix: ${{ steps.matrix.outputs.matrix }} + fullMatrix: ${{ steps.matrix.outputs.fullMatrix }} steps: - uses: actions/checkout@v4 @@ -99,9 +100,11 @@ jobs: - 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 @@ -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 }} @@ -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)) }} diff --git a/packages/mcl/dub.sdl b/packages/mcl/dub.sdl index ebdc1e48..7f8d5bfb 100644 --- a/packages/mcl/dub.sdl +++ b/packages/mcl/dub.sdl @@ -8,4 +8,3 @@ targetPath "build" dflags "-preview=shortenedMethods" dflags "-defaultlib=libphobos2.so" platform="dmd" lflags "-fuse-ld=gold" platform="dmd" -libs "curl" diff --git a/packages/mcl/src/main.d b/packages/mcl/src/main.d index 5231187a..95b75ac1 100644 --- a/packages/mcl/src/main.d +++ b/packages/mcl/src/main.d @@ -27,6 +27,7 @@ int main(string[] args) writeln("Running ", __traits(identifier, cmd)); cmd(); + writeln("Execution Succesfull"); return 0; } diff --git a/packages/mcl/src/src/mcl/commands/ci_matrix.d b/packages/mcl/src/src/mcl/commands/ci_matrix.d index 851d6c2b..5bfa1cfd 100755 --- a/packages/mcl/src/src/mcl/commands/ci_matrix.d +++ b/packages/mcl/src/src/mcl/commands/ci_matrix.d @@ -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; @@ -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)); @@ -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)