Skip to content

Commit

Permalink
chore: migrate from Earthly to Just for build and workflow automation
Browse files Browse the repository at this point in the history
This change replaces Earthly with Just by removing Earthfiles and
introducing a Justfile. Benefits include streamlining the dependency
management, simplifying workflow automation, and improving build
process readability.

Build and CI workflows (e.g., pre-commit, tests, linting) have been
adapted to utilize Just commands, ensuring consistency across
development processes.
  • Loading branch information
flemzord committed Dec 18, 2024
1 parent 6721cc2 commit 5988029
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 160 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ jobs:
with:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes" develop --impure --command earthly
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+pre-commit-nix
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes"
develop --impure --command just pre-commit
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
- name: Get changed files
Expand All @@ -63,11 +62,8 @@ jobs:
with:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes" develop --impure --command earthly
--no-output
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+tests --coverage=true
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes"
develop --impure --command just tests
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
- name: Upload coverage reports to Codecov with GitHub Action
Expand Down Expand Up @@ -99,8 +95,8 @@ jobs:
username: "NumaryBot"
password: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes" develop --impure --command earthly
--no-output
/nix/var/nix/profiles/default/bin/nix --extra-experimental-features "nix-command" --extra-experimental-features "flakes"
develop --impure --command earthly --no-output
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+release --mode=ci
env:
Expand Down
78 changes: 0 additions & 78 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ sources:
COPY main.go .
SAVE ARTIFACT /src

generate:
LOCALLY
RUN go generate ./...
SAVE ARTIFACT internal
SAVE ARTIFACT pkg
SAVE ARTIFACT cmd

compile:
LOCALLY
ARG VERSION=latest
Expand All @@ -44,41 +37,6 @@ build-image:
ARG tag=latest
DO --pass-args core+SAVE_IMAGE --COMPONENT=ledger --REPOSITORY=${REPOSITORY} --TAG=$tag

tests:
LOCALLY
ARG includeIntegrationTests="true"
ARG coverage=""
ARG debug=false
ARG additionalArgs=""

ENV DEBUG=$debug
ENV CGO_ENABLED=1 # required for -race

LET goFlags="-race"
IF [ "$coverage" = "true" ]
SET goFlags="$goFlags -covermode=atomic"
SET goFlags="$goFlags -coverpkg=github.com/formancehq/ledger/internal/..."
SET goFlags="$goFlags,github.com/formancehq/ledger/pkg/events/..."
SET goFlags="$goFlags,github.com/formancehq/ledger/pkg/accounts/..."
SET goFlags="$goFlags,github.com/formancehq/ledger/pkg/assets/..."
SET goFlags="$goFlags,github.com/formancehq/ledger/cmd/..."
SET goFlags="$goFlags -coverprofile coverage.txt"
END

IF [ "$includeIntegrationTests" = "true" ]
SET goFlags="$goFlags -tags it"
RUN go test $goFlags $additionalArgs ./...
ELSE
RUN go test $goFlags $additionalArgs ./...
END
IF [ "$coverage" = "true" ]
# as special case, exclude files suffixed by debug.go
# toremovelater: exclude machine code as it will be updated soon
RUN cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
RUN mv coverage2.txt coverage.txt
SAVE ARTIFACT coverage.txt
END

deploy:
COPY (+sources/*) /src
LET tag=$(tar cf - /src | sha1sum | awk '{print $1}')
Expand All @@ -91,35 +49,10 @@ deploy:
deploy-staging:
BUILD --pass-args core+deploy-staging

lint:
LOCALLY
RUN golangci-lint run --fix --build-tags it --timeout 5m
SAVE ARTIFACT cmd
SAVE ARTIFACT internal
SAVE ARTIFACT pkg
SAVE ARTIFACT test
SAVE ARTIFACT main.go

pre-commit:
BUILD +tidy
BUILD +lint
BUILD +openapi
BUILD +openapi-markdown
BUILD +generate
BUILD +generate-client
BUILD +export-docs-events
BUILD ./tools/*+pre-commit
BUILD ./deployments/*+pre-commit

pre-commit-nix:
LOCALLY
WAIT
BUILD +tidy
BUILD +lint
BUILD +generate
END
# BUILD +tests
BUILD +export-docs-events

openapi:
FROM node:20-alpine
Expand All @@ -138,12 +71,6 @@ openapi-markdown:
RUN widdershins openapi.yaml -o README.md --search false --language_tabs 'http:HTTP' --summary --omitHeader
SAVE ARTIFACT README.md AS LOCAL docs/api/README.md

tidy:
LOCALLY
RUN go mod tidy
SAVE ARTIFACT go.mod
SAVE ARTIFACT go.sum

release:
FROM core+builder-image
ARG mode=local
Expand Down Expand Up @@ -186,8 +113,3 @@ export-database-schema:
END
SAVE ARTIFACT docs/database/_system/diagrams AS LOCAL docs/database/_system/diagrams
SAVE ARTIFACT docs/database/_default/diagrams AS LOCAL docs/database/_default/diagrams

export-docs-events:
LOCALLY
RUN go run . docs events --write-dir docs/events
SAVE ARTIFACT docs/events
39 changes: 39 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
set dotenv-load

default:
@just --list

pre-commit: tidy lint generate export-docs-events earthly

earthly:
@earthly --no-output +pre-commit

[group('lint')]
lint:
@golangci-lint run --fix --build-tags it --timeout 5m
@cd {{justfile_directory()}}/tools/generator && golangci-lint run --fix --build-tags it --timeout 5m
@cd {{justfile_directory()}}/deployments/pulumi && golangci-lint run --fix --build-tags it --timeout 5m

tidy:
@go mod tidy
@cd {{justfile_directory()}}/tools/generator && go mod tidy
@cd {{justfile_directory()}}/deployments/pulumi && go mod tidy

generate:
@go generate ./...

export-docs-events:
@go run . docs events --write-dir docs/events

tests:
@go test -race -covermode=atomic \
-coverpkg=github.com/formancehq/ledger/internal/... \
-coverpkg=github.com/formancehq/ledger/pkg/events/... \
-coverpkg=github.com/formancehq/ledger/pkg/accounts/... \
-coverpkg=github.com/formancehq/ledger/pkg/assets/... \
-coverpkg=github.com/formancehq/ledger/cmd/... \
-coverprofile coverage.txt \
-tags it \
./...
@cat coverage.txt | grep -v debug.go | grep -v "/machine/" > coverage2.txt
@mv coverage2.txt coverage.txt
41 changes: 0 additions & 41 deletions deployments/pulumi/Earthfile

This file was deleted.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
mockgen
gomarkdoc
jdk11
just
];
};
});
Expand Down
38 changes: 7 additions & 31 deletions tools/generator/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,19 @@ CACHE --sharing=shared --id go-cache /root/.cache/go-build
sources:
FROM core+builder-image

COPY ../..+lint/pkg /src/pkg
COPY ../..+lint/internal /src/internal
COPY ../..+lint/cmd /src/cmd
COPY ../..+lint/*.go /src/
COPY ../..+tidy/go.mod /src/
COPY ../..+tidy/go.sum /src/
COPY ../../pkg /src/pkg
COPY ../../internal /src/internal
COPY ../../cmd /src/cmd
COPY ../../*.go /src/
COPY ../../go.mod /src/
COPY ../../go.sum /src/

WORKDIR /src/tools/generator
COPY --dir cmd examples .
COPY go.* *.go .

SAVE ARTIFACT /src

tidy:
FROM +sources
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
RUN go mod tidy

SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

compile:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
Expand All @@ -47,19 +38,4 @@ build-image:
COPY examples /examples
ARG REPOSITORY=ghcr.io
ARG tag=latest
DO --pass-args core+SAVE_IMAGE --COMPONENT=ledger-generator --REPOSITORY=${REPOSITORY} --TAG=$tag

lint:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
CACHE --id golangci-cache /root/.cache/golangci-lint

RUN golangci-lint run --fix --build-tags it --timeout 5m

SAVE ARTIFACT cmd AS LOCAL cmd
SAVE ARTIFACT main.go AS LOCAL main.go

pre-commit:
BUILD +tidy
BUILD +lint
DO --pass-args core+SAVE_IMAGE --COMPONENT=ledger-generator --REPOSITORY=${REPOSITORY} --TAG=$tag

0 comments on commit 5988029

Please sign in to comment.