|
| 1 | +VERSION 0.7 |
| 2 | +IMPORT github.com/poshcode/tasks |
| 3 | +FROM mcr.microsoft.com/dotnet/sdk:8.0 |
| 4 | +WORKDIR /work |
| 5 | + |
| 6 | +ARG --global EARTHLY_GIT_ORIGIN_URL |
| 7 | +ARG --global EARTHLY_BUILD_SHA |
| 8 | +ARG --global EARTHLY_GIT_BRANCH |
| 9 | +# These are my common paths, used in my shared /Tasks repo |
| 10 | +ARG --global OUTPUT_ROOT=/Modules |
| 11 | +ARG --global TEST_ROOT=/Tests |
| 12 | +ARG --global TEMP_ROOT=/temp |
| 13 | +# These are my common build args, used in my shared /Tasks repo |
| 14 | +ARG --global MODULE_NAME=ErrorView |
| 15 | +ARG --global CONFIGURATION=Release |
| 16 | + |
| 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 |
| 30 | + |
| 31 | +worker: |
| 32 | + # Dotnet tools and scripts installed by PSGet |
| 33 | + ENV PATH=$HOME/.dotnet/tools:$HOME/.local/share/powershell/Scripts:$PATH |
| 34 | + RUN mkdir /Tasks \ |
| 35 | + && git config --global user.email "[email protected]" \ |
| 36 | + && git config --global user.name "Earthly Build" |
| 37 | + # I'm using Invoke-Build tasks from this other repo which rarely changes |
| 38 | + COPY tasks+tasks/* /Tasks |
| 39 | + # Dealing with dependencies first allows docker to cache packages for us |
| 40 | + # So the dependency cach only re-builds when you add a new dependency |
| 41 | + COPY RequiredModules.psd1 . |
| 42 | + # COPY --if-exists *.csproj . |
| 43 | + RUN ["pwsh", "-File", "/Tasks/_Bootstrap.ps1", "-RequiredModulesPath", "RequiredModules.psd1"] |
| 44 | + |
| 45 | +build: |
| 46 | + FROM +worker |
| 47 | + RUN mkdir $OUTPUT_ROOT $TEST_ROOT $TEMP_ROOT |
| 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 --if-exists --dir .git/ source/ build.psd1 Build.build.ps1 GitVersion.yml nuget.config /work |
| 52 | + RUN ["pwsh", "-Command", "Invoke-Build", "-Task", "Build", "-File", "Build.build.ps1"] |
| 53 | + |
| 54 | + # SAVE ARTIFACT [--keep-ts] [--keep-own] [--if-exists] [--force] <src> [<artifact-dest-path>] [AS LOCAL <local-path>] |
| 55 | + SAVE ARTIFACT $OUTPUT_ROOT/$MODULE_NAME AS LOCAL ./Modules/$MODULE_NAME |
| 56 | + |
| 57 | +test: |
| 58 | + # If we run a target as a reference in FROM or COPY, it's outputs will not be produced |
| 59 | + # BUILD +build |
| 60 | + FROM +build |
| 61 | + # Copy the test files here, so we can avoid rebuilding when iterating on tests |
| 62 | + COPY --if-exists --dir Tests/ ScriptAnalyzerSettings.psd1 /work |
| 63 | + RUN ["pwsh", "-Command", "Invoke-Build", "-Task", "Test", "-File", "Build.build.ps1"] |
| 64 | + |
| 65 | + # SAVE ARTIFACT [--keep-ts] [--keep-own] [--if-exists] [--force] <src> [<artifact-dest-path>] [AS LOCAL <local-path>] |
| 66 | + SAVE ARTIFACT $TEST_ROOT AS LOCAL ./Modules/$MODULE_NAME-TestResults |
| 67 | + |
| 68 | +# pack: |
| 69 | +# BUILD +test # So that we get the module artifact from build too |
| 70 | +# FROM +test |
| 71 | +# RUN ["pwsh", "-Command", "Invoke-Build", "-Task", "Pack", "-File", "Build.build.ps1", "-Verbose"] |
| 72 | +# SAVE ARTIFACT $OUTPUT_ROOT/publish/*.nupkg AS LOCAL ./Modules/$MODULE_NAME-Packages/ |
| 73 | + |
| 74 | +push: |
| 75 | + FROM +build |
| 76 | + RUN --push --secret NUGET_API_KEY --secret PSGALLERY_API_KEY -- \ |
| 77 | + pwsh -Command Invoke-Build -Task Push -File Build.build.ps1 -Verbose |
| 78 | + |
| 79 | +all: |
| 80 | + # BUILD +build |
| 81 | + BUILD +test |
| 82 | + BUILD +push |
0 commit comments