2024-03-18 15:25:19 -04:00
|
|
|
VERSION 0.8
|
2022-04-21 14:08:59 -07:00
|
|
|
|
2024-03-26 12:44:05 -04:00
|
|
|
PROJECT earthly-technologies/core
|
|
|
|
|
2024-03-26 14:01:47 -04:00
|
|
|
ARG EARTHLY_LIB_VERSION=3.0.1
|
|
|
|
IMPORT github.com/earthly/lib/utils/git:$EARTHLY_LIB_VERSION AS git
|
|
|
|
|
2021-04-20 15:28:53 -07:00
|
|
|
npm-base:
|
2024-03-18 15:25:19 -04:00
|
|
|
FROM node:21.7-alpine3.19
|
2022-04-18 18:30:58 -07:00
|
|
|
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
|
2021-04-20 15:28:53 -07:00
|
|
|
|
|
|
|
code:
|
|
|
|
FROM +npm-base
|
|
|
|
WORKDIR /code
|
|
|
|
COPY package.json package-lock.json .
|
|
|
|
RUN npm ci
|
|
|
|
COPY --dir src .
|
|
|
|
|
|
|
|
lint:
|
|
|
|
FROM +code
|
2024-03-27 14:37:24 -04:00
|
|
|
COPY .eslintrc.cjs .
|
2022-04-18 18:30:58 -07:00
|
|
|
RUN npm run-script lint
|
2021-04-20 15:28:53 -07:00
|
|
|
|
|
|
|
compile:
|
|
|
|
FROM +code
|
|
|
|
WORKDIR /code
|
|
|
|
RUN npm ci
|
2022-04-18 18:30:58 -07:00
|
|
|
COPY tsconfig.json .
|
|
|
|
RUN npm run-script package
|
2021-04-20 15:28:53 -07:00
|
|
|
SAVE ARTIFACT dist AS LOCAL dist
|
|
|
|
SAVE ARTIFACT node_modules AS LOCAL node_modules
|
|
|
|
|
2022-04-21 14:08:59 -07:00
|
|
|
test-compile-was-run:
|
2024-01-23 11:49:50 -08:00
|
|
|
FROM alpine:3.19
|
2022-04-21 14:08:59 -07:00
|
|
|
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)
|
|
|
|
|
2022-04-18 18:30:58 -07:00
|
|
|
test:
|
|
|
|
FROM +code
|
|
|
|
COPY tsconfig.json .
|
2024-03-27 14:37:24 -04:00
|
|
|
COPY vite.config.ts vitest.config.ts .
|
2022-04-18 18:30:58 -07:00
|
|
|
RUN npm test
|
|
|
|
|
2022-04-21 14:08:59 -07:00
|
|
|
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"
|
2022-09-20 17:00:53 -06:00
|
|
|
# [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
|
2022-04-21 14:08:59 -07:00
|
|
|
|
|
|
|
# validate cache was used
|
|
|
|
RUN node dist/setup/index.js | tee output2
|
|
|
|
RUN grep 'Found tool in cache' output2
|
|
|
|
|
|
|
|
lint-newline:
|
2024-01-23 11:49:50 -08:00
|
|
|
FROM alpine:3.19
|
2022-04-21 14:08:59 -07:00
|
|
|
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
|
|
|
|
|
2024-03-26 14:01:47 -04:00
|
|
|
update-dist-for-renovate:
|
2024-03-26 10:28:15 -04:00
|
|
|
FROM alpine/git
|
2024-03-26 14:01:47 -04:00
|
|
|
RUN git config --global user.name "renovate[bot]" && \
|
|
|
|
git config --global user.email "renovate[bot]@users.noreply.github.com" && \
|
2024-03-26 10:28:15 -04:00
|
|
|
git config --global url."git@github.com:".insteadOf "https://github.com/"
|
|
|
|
|
|
|
|
ARG git_repo="earthly/actions-setup"
|
|
|
|
ARG git_url="git@github.com:$git_repo"
|
|
|
|
ARG SECRET_PATH=littleredcorvette-id_rsa
|
2024-03-26 14:01:47 -04:00
|
|
|
DO --pass-args git+DEEP_CLONE --GIT_URL=$git_url --SECRET_PATH=$SECRET_PATH
|
2024-03-26 10:28:15 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-03-26 12:44:05 -04:00
|
|
|
merge-release-to-major-branch:
|
|
|
|
FROM alpine/git
|
|
|
|
RUN git config --global user.name "littleredcorvette" && \
|
|
|
|
git config --global user.email "littleredcorvette@users.noreply.github.com" && \
|
|
|
|
git config --global url."git@github.com:".insteadOf "https://github.com/"
|
|
|
|
|
|
|
|
ARG git_repo="earthly/actions-setup"
|
|
|
|
ARG git_url="git@github.com:$git_repo"
|
|
|
|
ARG SECRET_PATH=littleredcorvette-id_rsa
|
2024-03-26 14:01:47 -04:00
|
|
|
DO --pass-args git+DEEP_CLONE --GIT_URL=$git_url --SECRET_PATH=$SECRET_PATH
|
2024-03-26 12:44:05 -04:00
|
|
|
|
|
|
|
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 \
|
2024-03-26 14:01:47 -04:00
|
|
|
git checkout $major && git merge --ff-only $tag
|
2024-03-26 12:44:05 -04:00
|
|
|
RUN --push --mount=type=secret,id=$SECRET_PATH,mode=0400,target=/root/.ssh/id_rsa \
|
|
|
|
git push origin $major
|
2022-04-21 14:08:59 -07:00
|
|
|
|
2021-04-20 15:28:53 -07:00
|
|
|
all:
|
|
|
|
BUILD +lint
|
2022-04-21 14:08:59 -07:00
|
|
|
BUILD +lint-newline
|
2021-04-20 15:28:53 -07:00
|
|
|
BUILD +compile
|
2022-04-18 18:30:58 -07:00
|
|
|
BUILD +test
|
2022-04-21 14:08:59 -07:00
|
|
|
BUILD +test-run
|
|
|
|
BUILD +test-compile-was-run
|