-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathbuild.earth
More file actions
63 lines (57 loc) · 2.6 KB
/
Copy pathbuild.earth
File metadata and controls
63 lines (57 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
VERSION 0.8
IMPORT github.com/poshcode/tasks:feature/ld AS tasks
FROM mcr.microsoft.com/dotnet/sdk:10.0
WORKDIR /earth
# My build scripts use this to detect they're running in Earthly
ARG --global EARTHLY_VERSION
ARG --global EARTHLY_PUSH
# These are my common paths, used in my shared /Tasks repo
ARG --global IB_OUTPUT_ROOT=/output
ARG --global IB_RESULTS_ROOT=/results
ARG --global IB_TEMP_ROOT=/temp
ARG --global IB_TASK_ROOT=/tasks
# These are Build args, used by powershell/base in my shared /Tasks repo
ARG --global IB_MODULE_NAME=ModuleBuilder
ARG --global IB_CONFIGURATION=Release
# initialize installs build dependencies and packages
initialize:
# Dotnet tools and scripts installed by PSGet
ENV PATH=$HOME/.dotnet/tools:$HOME/.local/share/powershell/Scripts:$IB_TASK_ROOT/scripts:$PATH
RUN mkdir $IB_TASK_ROOT $IB_OUTPUT_ROOT $IB_RESULTS_ROOT $IB_TEMP_ROOT \
&& git config --global user.email "Jaykul@HuddledMasses.org" \
&& git config --global user.name "Earth Build"
# I'm using Invoke-Build tasks from this other repo which rarely changes
COPY tasks+tasks/* $IB_TASK_ROOT
# Dealing with dependencies first allows them to be cached
COPY build.build.ps1 .
COPY build.requires.psd1 .
COPY --if-exists dotnet-tools.json .
COPY --if-exists .config/dotnet-tools.json .
# COPY --if-exists **/*.csproj .
RUN ["pwsh", "-Command", "Invoke-Build -Task Initialize"]
# build produces the main output but does not package or test it
build:
# These are defined to make them available as information for the build scripts
ARG EARTHLY_GIT_BRANCH
FROM +initialize
# make sure you have output folders (like bin, obj, Modules) in .earthlyignore
COPY . .
RUN ["pwsh", "-Command", "Invoke-Build -Task Build, Pack"]
# SAVE ARTIFACT [--keep-ts] [--keep-own] [--if-exists] [--force] <src> [<artifact-dest-path>] [AS LOCAL <local-path>]
SAVE ARTIFACT $IB_OUTPUT_ROOT/$IB_MODULE_NAME AS LOCAL ./output/$IB_MODULE_NAME
# test runs the tests and probably fails if the tests fail
test:
ARG EARTHLY_GIT_BRANCH
BUILD +build
FROM +build
RUN ["pwsh", "-Command", "Invoke-Build -Task Test"]
SAVE ARTIFACT $IB_RESULTS_ROOT AS LOCAL ./output$IB_RESULTS_ROOT
# publish runs publish and push tasks if the tests pass and --push was specified.
# It needs the API keys to be passed in as secrets
all:
ARG EARTHLY_GIT_BRANCH
# If we only reference with FROM (or COPY) the outputs will not be produced
BUILD +test
FROM +build
RUN --push --secret IB_PS_PUBLISH_KEY --secret GITHUB_TOKEN \
-- pwsh -Command "Invoke-Build -Task Push" -Verbose