Skip to content

Commit

Permalink
Add CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Mar 20, 2024
1 parent c44aaae commit b59c047
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 8 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ on:
os:
required: true
type: string
target:
required: false
type: string
default: "all-crates"
secrets:
cachix-token:
required: true

jobs:
build:
name: Build all crates
name: "Build ${{ inputs.target }}"
runs-on: "${{ inputs.os }}"
steps:
- name: Set $USER if needed
Expand All @@ -28,4 +32,4 @@ jobs:
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
- run: nix build .#all-crates -L --accept-flake-config
- run: nix build .#${{ inputs.target }} -L --accept-flake-config
41 changes: 41 additions & 0 deletions .github/workflows/cd-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CD Check Pipeline

concurrency:
group: cd-check-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
merge_group:

pull_request:
branches:
- "release"
- "release/*"
types:
- opened
- synchronize

jobs:
build-linux-x86_64:
name: "Linux x86_64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-linux-aarch64:
name: "Linux aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-macos-aarch64:
name: "MacOS aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
20 changes: 20 additions & 0 deletions .github/workflows/cd-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CD Release Pipeline

concurrency:
group: cd-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: ["add-cd"]
tags:
- "*/*"

jobs:
release:
name: "Release sink-mongo"
uses: ./.github/workflows/cd-release.yml
with:
target: sink-mongo
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
95 changes: 95 additions & 0 deletions .github/workflows/cd-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release a target

on:
workflow_call:
inputs:
target:
required: true
type: string
secrets:
cachix-token:
required: true

jobs:
# Step 1: build the target for all platforms

build-linux-x86_64:
name: "Linux x86_64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-linux-aarch64:
name: "Linux aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-macos-aarch64:
name: "MacOS aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

# Step 2a: create release archive for all platforms

build-linux-x86_64-archive:
name: "Linux x86_64: Build archive"
needs: build-linux-x86_64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
target: ${{ inputs.target }}-archive
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-linux-aarch64-archive:
name: "Linux aarch64: Build archive"
needs: build-linux-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
target: ${{ inputs.target }}-archive
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-macos-aarch64-archive:
name: "MacOS aarch64: Build archive"
needs: build-macos-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
target: ${{ inputs.target }}-archive
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

# Step 2b: create Docker image for all (Linux) platforms.

build-linux-x86_64-image:
name: "Linux x86_64: Build Docker image"
needs: build-linux-x86_64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
target: ${{ inputs.target }}-image
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-linux-aarch64-image:
name: "Linux aarch64: Build Docker image"
needs: build-linux-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
target: ${{ inputs.target }}-image
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ on:
- opened
- synchronize

push:
branches:
- "main"

jobs:
check:
name: "Checks"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ We switched to merge commits for PRs for the following reasons:
learn more about backporting fixes.
- Start by opening a PR from `main` into `release`. This PR should contain no
changes other than changes to the CHANGELOGs and version numbers.
- The `release-check.yml` pipeline is executed. This pipeline simply builds the
- The `cd-check.yml` pipeline is executed. This pipeline simply builds the
binaries (we follow the ["not rocket
science"](https://graydon2.dreamwidth.org/1597.html) rule).
- Once the PR is merged, nothing happens.
Expand Down
22 changes: 21 additions & 1 deletion nix/crates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ let
in
pkgs.lib.attrsets.mapAttrs' mkUniversal binaries;

binariesArchive =
let
mkArchive = name: value: {
name = "${name}-archive";
value = pkgs.stdenv.mkDerivation {
name = "${name}-archive";
buildInputs = [
value
pkgs.gzip
];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out
gzip -c ${value}/bin/* > $out/${name}.gz
'';
};
};
in
pkgs.lib.attrsets.mapAttrs' mkArchive binariesUniversal;

# Ubuntu-based Docker images.
imagesUbuntu =
let
Expand Down Expand Up @@ -313,7 +333,7 @@ in

binaries = builtins.attrNames binariesUniversal;

packages = images // imagesUbuntu // binariesUniversal // {
packages = images // imagesUbuntu // binariesUniversal // binariesArchive // {
all-crates = allCrates;
unit-tests = unitTests;
integration-tests-archive = integrationTestsArchive;
Expand Down

0 comments on commit b59c047

Please sign in to comment.