diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 8efb1f5..2eda71b 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,58 +1,109 @@ -name: Build, Test, and publish Docker image +name: "pipeline" on: push: branches: ['main'] - paths: -# this ensures that docker image is only published when source code or Dockerfile is changed - - 'src/**' - - 'tests/**' - - 'Dockerfile' -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + pull_request: + branches: ['main'] -jobs: - build-and-test-linux: +jobs: + setup: runs-on: ubuntu-latest + outputs: + + # changed files output, might be relevant for other jobs + global_any_modified: ${{ steps.changed-files-yaml.outputs.global_any_modified }} + global_all_modified_files: ${{ steps.changed-files-yaml.outputs.global_all_modified_files }} + + tests_all_modified_files: ${{ steps.changed-files-yaml.outputs.tests_all_modified_files }} + tests_any_modified: ${{ steps.changed-files-yaml.outputs.tests_any_modified }} + + src_all_modified_files: ${{ steps.changed-files-yaml.outputs.src_all_modified_files }} + src_any_modified: ${{ steps.changed-files-yaml.outputs.src_any_modified }} + + dockerfile_modified: ${{ steps.changed-files-yaml.outputs.dockerfile_any_modified }} + + # trigger other jobs + trigger-build-and-test: ${{steps.set-triggers.outputs.trigger-build-and-test}} + trigger-release-docker: ${{steps.set-triggers.outputs.trigger-release-docker}} steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.x.x - - name: make script executable - run: chmod u+x build.sh - - name: Build and test - working-directory: ./ - run: ./build.sh runtests - - build-and-push-image: -# only publish docker images when tests succeed - needs: [build-and-test-linux] + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. + - name: Get all relevant file changes + id: changed-files-yaml + uses: tj-actions/changed-files@v42 + with: + files_yaml: | + global: + - '**' + tests: + - tests/** + src: + - src/** + dockerfile: + - Dockerfile + + - name: set triggers + id: set-triggers + run: | + echo "trigger-build-and-test=${{ steps.changed-files-yaml.outputs.tests_any_modified == 'true' || steps.changed-files-yaml.outputs.src_any_modified == 'true' }}" >> $GITHUB_OUTPUT + echo "trigger-release-docker=${{ github.event_name == 'push' && (steps.changed-files-yaml.outputs.tests_any_modified == 'true' || steps.changed-files-yaml.outputs.src_any_modified == 'true' || steps.changed-files-yaml.outputs.dockerfile_modified == 'true') }}" >> $GITHUB_OUTPUT + + echo "$GITHUB_OUTPUT" + + - name: list outputs + run: | + echo "global:" + echo "- any: ${{ steps.changed-files-yaml.outputs.global_any_modified }}" + echo "- all: ${{ steps.changed-files-yaml.outputs.global_all_modified_files }}" + echo "tests:" + echo "- any: ${{ steps.changed-files-yaml.outputs.tests_any_modified }}" + echo "- all: ${{ steps.changed-files-yaml.outputs.tests_all_modified_files }}" + echo "src:" + echo "- any: ${{ steps.changed-files-yaml.outputs.src_any_modified }}" + echo "- all: ${{ steps.changed-files-yaml.outputs.src_all_modified_files }}" + echo "dockerfile: ${{ steps.changed-files-yaml.outputs.dockerfile_modified }}" + echo "computed outputs:" + echo "trigger build-and-test: ${{steps.set-triggers.outputs.trigger-build-and-test}}" + echo "trigger docker release: ${{steps.set-triggers.outputs.trigger-release-docker}}" + + - name: list triggered jobs + run: | + echo "this should trigger the following jobs:" + echo "build-and-test-projects: ${{steps.set-triggers.outputs.trigger-build-and-test}}" + echo "release-docker-image: ${{steps.set-triggers.outputs.trigger-release-docker}}" + + build-and-test: + name: "Build and test" + needs: setup + # https://github.com/actions/runner/issues/1173 + if: needs.setup.outputs.trigger-build-and-test == 'true' + uses: nfdi4plants/arc-validate-package-registry/.github/workflows/build-and-test-solution.yml@main + with: + solution: ./arc-export.sln + configuration: Release + + release-docker-image: + name: "Release Docker image" + needs: [setup, build-and-test] + if: needs.setup.outputs.trigger-release-docker == 'true' runs-on: ubuntu-latest + env: + REGISTRY: ghcr.io + IMAGE_NAME: nfdi4plants/arc-export permissions: contents: read packages: write - steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.x.x - - name: make script executable - run: chmod u+x build.sh - - name: Build and test - working-directory: ./ - run: ./build.sh publishbinarieslinux - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v3.0.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -60,14 +111,15 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5.5.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v5.1.0 with: context: . + file: ./Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 5c0227d..2236aea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,22 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0 +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS base +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY "src/arc-export" . +RUN dotnet restore "./arc-export.fsproj" +RUN dotnet build "./arc-export.fsproj" -c $BUILD_CONFIGURATION -o /build -COPY publish/linux-x64/arc-export . +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./arc-export.fsproj" -c $BUILD_CONFIGURATION -o /publish -#ENTRYPOINT ["/arc-export"] \ No newline at end of file +FROM base AS final +COPY --from=publish /publish . + +#FROM mcr.microsoft.com/dotnet/sdk:6.0 +# +# +#COPY publish/linux-x64/arc-export . +# +##ENTRYPOINT ["/arc-export"] \ No newline at end of file diff --git a/arc-export.sln b/arc-export.sln index c65e54d..883cd91 100644 --- a/arc-export.sln +++ b/arc-export.sln @@ -5,20 +5,11 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{50F222B5-E207-40FD-B817-AFBF497C83BD}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{9C7BD557-3958-4BBB-8D57-3AAFA4B7CFE1}" - ProjectSection(SolutionItems) = preProject - build.cmd = build.cmd - build.sh = build.sh - Dockerfile = Dockerfile - global.json = global.json - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F9989126-C2C0-450A-ACD2-D8C5C28DD28C}" EndProject -Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "build", "build\build.fsproj", "{B29B2B22-15CE-4F48-B6C4-075FF853BFB0}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{DF2FB84A-1A8C-435E-B61D-16D94BEA70B9}" ProjectSection(SolutionItems) = preProject + Dockerfile = Dockerfile global.json = global.json LICENSE = LICENSE README.md = README.md @@ -46,10 +37,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B29B2B22-15CE-4F48-B6C4-075FF853BFB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B29B2B22-15CE-4F48-B6C4-075FF853BFB0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B29B2B22-15CE-4F48-B6C4-075FF853BFB0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B29B2B22-15CE-4F48-B6C4-075FF853BFB0}.Release|Any CPU.Build.0 = Release|Any CPU {4C8F9483-D970-4D29-AEE2-2A71642ED6DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4C8F9483-D970-4D29-AEE2-2A71642ED6DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C8F9483-D970-4D29-AEE2-2A71642ED6DA}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -63,7 +50,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {B29B2B22-15CE-4F48-B6C4-075FF853BFB0} = {9C7BD557-3958-4BBB-8D57-3AAFA4B7CFE1} {4C8F9483-D970-4D29-AEE2-2A71642ED6DA} = {50F222B5-E207-40FD-B817-AFBF497C83BD} {5DDD8233-173C-4529-8EAB-EF778E029850} = {F9989126-C2C0-450A-ACD2-D8C5C28DD28C} EndGlobalSection