-
Notifications
You must be signed in to change notification settings - Fork 8
/
Earthfile
148 lines (130 loc) · 4.98 KB
/
Earthfile
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
VERSION 0.8
PROJECT earthly-technologies/core
ARG EARTHLY_LIB_VERSION=3.0.1
IMPORT github.com/earthly/lib/utils/git:$EARTHLY_LIB_VERSION AS git
npm-base:
FROM node:21.7-alpine3.19
COPY ./package.json ./
COPY ./package-lock.json ./
RUN npm install
# Output these back in case npm install changes them.
SAVE ARTIFACT package.json AS LOCAL ./package.json
SAVE ARTIFACT package-lock.json AS LOCAL ./package-lock.json
code:
FROM +npm-base
WORKDIR /code
COPY package.json package-lock.json .
RUN npm ci
COPY --dir src .
lint:
FROM +code
COPY .eslintrc.cjs .
RUN npm run-script lint
compile:
FROM +code
WORKDIR /code
RUN npm ci
COPY tsconfig.json .
RUN npm run-script package
SAVE ARTIFACT dist AS LOCAL dist
SAVE ARTIFACT node_modules AS LOCAL node_modules
test-compile-was-run:
FROM alpine:3.20
COPY dist /from-git
COPY +compile/dist /from-compile
RUN diff -r /from-git /from-compile >/dev/null || (echo "dist and +compile/dist are different, did you forget to run earthly +compile?" && exit 1)
test:
FROM +code
COPY tsconfig.json .
COPY vite.config.ts vitest.config.ts .
RUN npm test
test-run:
FROM +npm-base
COPY --dir +compile/dist .
ENV RUNNER_TOOL_CACHE=/tmp/cache-dir
RUN node dist/setup/index.js | tee output
RUN ! grep 'Found tool in cache' output
RUN cat output | grep '^::add-path::' | sed 's/::add-path:://g' > earthly-path
RUN test "$(cat earthly-path)" = "/root/.earthly/bin"
# [a-zA-Z0-9]* attempt to match a commit hash
RUN export PATH="$(cat earthly-path):$PATH" && earthly --version | tee version.output
RUN grep '^earthly version v.*linux/amd64; Alpine Linux' version.output
# validate cache was used
RUN node dist/setup/index.js | tee output2
RUN grep 'Found tool in cache' output2
lint-newline:
FROM alpine:3.20
WORKDIR /everything
COPY . .
# test that line endings are unix-style
RUN set -e; \
code=0; \
for f in $(find . -type f \( -iname '*.ts' -o -iname 'Earthfile' \) | grep -v node_modules); do \
if ! dos2unix < "$f" | cmp - "$f"; then \
echo "$f contains windows-style newlines and must be converted to unix-style (use dos2unix to fix)"; \
code=1; \
fi; \
done; \
exit $code
# test file ends with a single newline
RUN set -e; \
code=0; \
for f in $(find . -type f \( -iname '*.ts' -o -iname 'Earthfile' \) | grep -v node_modules); do \
if [ "$(tail -c 1 $f)" != "$(printf '\n')" ]; then \
echo "$f does not end with a newline"; \
code=1; \
fi; \
done; \
exit $code
# check for files with trailing newlines
RUN set -e; \
code=0; \
for f in $(find . -type f \( -iname '*.ts' -o -iname 'Earthfile' \) | grep -v node_modules); do \
if [ "$(tail -c 2 $f)" == "$(printf '\n\n')" ]; then \
echo "$f has trailing newlines"; \
code=1; \
fi; \
done; \
exit $code
update-dist-for-renovate:
FROM alpine/git
RUN git config --global user.name "renovate[bot]" && \
git config --global user.email "renovate[bot]@users.noreply.github.com" && \
git config --global url."[email protected]:".insteadOf "https://github.com/"
ARG git_repo="earthly/actions-setup"
ARG git_url="[email protected]:$git_repo"
ARG SECRET_PATH=littleredcorvette-id_rsa
DO --pass-args git+DEEP_CLONE --GIT_URL=$git_url --SECRET_PATH=$SECRET_PATH
ARG EARTHLY_GIT_BRANCH
LET branch=$EARTHLY_GIT_BRANCH
RUN --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \
git checkout $branch
COPY --dir +compile/dist .
RUN git add dist && git commit -m "update dist for Renovate" || echo nothing to commit
RUN --push --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \
git push origin $branch
merge-release-to-major-branch:
FROM alpine/git
RUN git config --global user.name "littleredcorvette" && \
git config --global user.email "[email protected]" && \
git config --global url."[email protected]:".insteadOf "https://github.com/"
ARG git_repo="earthly/actions-setup"
ARG git_url="[email protected]:$git_repo"
ARG SECRET_PATH=littleredcorvette-id_rsa
DO --pass-args git+DEEP_CLONE --GIT_URL=$git_url --SECRET_PATH=$SECRET_PATH
ARG --required RELEASE_TAG
LET tag=${RELEASE_TAG#refs/tags/}
LET major=$tag
SET major=$(echo ${major%.*})
SET major=$(echo ${major%.*})
RUN --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \
git checkout $major && git merge --ff-only $tag
RUN --push --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \
git push origin $major
all:
BUILD +lint
BUILD +lint-newline
BUILD +compile
BUILD +test
BUILD +test-run
BUILD +test-compile-was-run