|
| 1 | +lib: { |
| 2 | + default_branch, |
| 3 | + platform, |
| 4 | + withNixbuild, |
| 5 | + withPersistentDiscovery, |
| 6 | +}: let |
| 7 | + aws = import ./aws.nix; |
| 8 | + installNixAction = {uses = "blaggacao/nix-quick-install-action@detect-nix-flakes-config";}; |
| 9 | + useNixbuildAction = { |
| 10 | + uses = "nixbuild/nixbuild-action@v17"; |
| 11 | + "with" = { |
| 12 | + nixbuild_ssh_key = "\${{ secrets.SSH_KEY }}"; |
| 13 | + generate_summary_for = "job"; |
| 14 | + }; |
| 15 | + }; |
| 16 | + discoverAction = { |
| 17 | + uses = "divnix/std-action/discover@main"; |
| 18 | + id = "discovery"; |
| 19 | + }; |
| 20 | + runAction = {uses = "divnix/std-action/run@main";}; |
| 21 | + # Jobs |
| 22 | + discover = { |
| 23 | + outputs.hits = "\${{ steps.discovery.outputs.hits }}"; |
| 24 | + runs-on = "ubuntu-latest"; |
| 25 | + steps = |
| 26 | + [] |
| 27 | + # account is part of ecr url, thus part of `hits` output and needs to pass so we can't mask it |
| 28 | + ++ lib.optionals (platform == "aws") [lib.recursiveUpdate aws.credentials {mask-aws-account-id = false;}] |
| 29 | + ++ lib.optionals (platform == "aws") [aws.ecr] |
| 30 | + ++ lib.optionals (!withPersistentDiscovery) [installNixAction] |
| 31 | + ++ lib.optionals withNixbuild [useNixbuildAction] |
| 32 | + ++ [discoverAction]; |
| 33 | + }; |
| 34 | + worker = { |
| 35 | + block, |
| 36 | + action, |
| 37 | + needs ? [], |
| 38 | + steps ? [], |
| 39 | + }: { |
| 40 | + needs = ["discover"] ++ needs; |
| 41 | + name = "\${{ matrix.target.jobName }}"; |
| 42 | + "if" = "fromJSON(needs.discover.outputs.hits).${block}.${action} != '{}'"; |
| 43 | + strategy = { |
| 44 | + fail-fast = false; |
| 45 | + matrix.target = "\${{ fromJSON(needs.discover.outputs.hits).${block}.${action} }}"; |
| 46 | + }; |
| 47 | + steps = |
| 48 | + [] |
| 49 | + ++ [installNixAction] |
| 50 | + ++ lib.optionals withNixbuild [useNixbuildAction] |
| 51 | + ++ [runAction]; |
| 52 | + }; |
| 53 | +in { |
| 54 | + name = "CI/CD"; |
| 55 | + on = { |
| 56 | + pull_request.branches = [default_branch]; |
| 57 | + push.branches = [default_branch]; |
| 58 | + }; |
| 59 | + permissions = { |
| 60 | + id-token = "write"; |
| 61 | + contents = "read"; |
| 62 | + }; |
| 63 | + concurrency = { |
| 64 | + group = ''std-''${{ github.workflow }}-''${{ runner.os }}-''${{ github.ref }}''; |
| 65 | + "cancel-in-progress" = true; |
| 66 | + }; |
| 67 | + jobs = { |
| 68 | + inherit discover; |
| 69 | + build = worker { |
| 70 | + block = "packages"; |
| 71 | + action = "build"; |
| 72 | + }; |
| 73 | + images = worker { |
| 74 | + block = "images"; |
| 75 | + action = "publish"; |
| 76 | + needs = ["build"]; |
| 77 | + steps = |
| 78 | + lib.optionals (platform == "aws") [aws.credentials] |
| 79 | + lib.optionals (platform == "aws") [aws.ecr]; |
| 80 | + }; |
| 81 | + deploy = worker { |
| 82 | + block = "deployments"; |
| 83 | + action = "apply"; |
| 84 | + needs = ["images"]; |
| 85 | + steps = |
| 86 | + lib.optionals (platform == "aws") [aws.credentials]; |
| 87 | + }; |
| 88 | + }; |
| 89 | +} |
0 commit comments