Skip to content

Commit cdf718f

Browse files
committed
Some improvements to the earthly build
1 parent feb6793 commit cdf718f

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

.earthlyignore

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
#.git/
2+
.vscode/
3+
.github/
4+
.gitignore
5+
.editorconfig
16
# ignore Modules (because we output there now)
2-
/Modules/*
3-
# These aren't part of the module (yet)
4-
/PotentialContribution/*
5-
/Content/*
7+
Modules/
8+
# For best performance, don't include README etc., to avoid cache-busting
9+
ReadMe.md
10+
LICENCE
11+
# Legacy build files
12+
build.ps1
13+
test.ps1
14+
Install-RequiredModule.ps1
15+
16+
# These aren't part of the actual module
17+
Templates/
18+
PotentialContribution/
19+
Content/
20+
Output/
21+
obj/
22+
bin/

Earthfile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ ARG --global TEMP_ROOT=/temp
1414
ARG --global MODULE_NAME=ModuleBuilder
1515
ARG --global CONFIGURATION=Release
1616

17+
# This works on Linux, and speeds things up dramatically because I don't need my .git folder
18+
# But "LOCALLY" doesn't work on Windows (yet), and that's my main dev environment
19+
# version:
20+
# COPY --if-exists GitVersion.yml .
21+
# IF [ -f ./GitVersion.yml ]
22+
# ELSE
23+
# LOCALLY
24+
# COPY tasks+tasks/tasks/GitVersion.yml .
25+
# END
26+
# LOCALLY
27+
# RUN dotnet tool update GitVersion.Tool --version 5.12.0 --global && \
28+
# dotnet gitversion > version.json
29+
# SAVE ARTIFACT ./version.json
1730

1831
worker:
1932
# Dotnet tools and scripts installed by PSGet
@@ -26,24 +39,27 @@ worker:
2639
# Dealing with dependencies first allows docker to cache packages for us
2740
# So the dependency cach only re-builds when you add a new dependency
2841
COPY RequiredModules.psd1 .
29-
# COPY *.csproj .
42+
# COPY --if-exists *.csproj .
3043
RUN ["pwsh", "-File", "/Tasks/_Bootstrap.ps1", "-RequiredModulesPath", "RequiredModules.psd1"]
3144

3245
build:
3346
FROM +worker
3447
RUN mkdir $OUTPUT_ROOT $TEST_ROOT $TEMP_ROOT
35-
COPY . .
36-
# make sure you have bin and obj in .earthlyignore, as their content from context might cause problems
48+
# On Linux we could use the version: task, we wouldn't need .git/ here and
49+
# we could avoid re-running this every time there was a commit
50+
# we could copying the Source and Invoke-Build script to improve caching
51+
COPY --dir .git/ Source/ build.psd1 Build.build.ps1 GitVersion.yml nuget.config /work
3752
RUN ["pwsh", "-Command", "Invoke-Build", "-Task", "Build", "-File", "Build.build.ps1"]
3853

3954
# SAVE ARTIFACT [--keep-ts] [--keep-own] [--if-exists] [--force] <src> [<artifact-dest-path>] [AS LOCAL <local-path>]
4055
SAVE ARTIFACT $OUTPUT_ROOT/$MODULE_NAME AS LOCAL ./Modules/$MODULE_NAME
4156

4257
test:
4358
# If we run a target as a reference in FROM or COPY, it's outputs will not be produced
44-
BUILD +build
59+
# BUILD +build
4560
FROM +build
46-
# make sure you have bin and obj in .earthlyignore, as their content from context might cause problems
61+
# Copy the test files here, so we can avoid rebuilding when iterating on tests
62+
COPY --dir Tests/ ScriptAnalyzerSettings.psd1 /work
4763
RUN ["pwsh", "-Command", "Invoke-Build", "-Task", "Test", "-File", "Build.build.ps1"]
4864

4965
# SAVE ARTIFACT [--keep-ts] [--keep-own] [--if-exists] [--force] <src> [<artifact-dest-path>] [AS LOCAL <local-path>]

0 commit comments

Comments
 (0)