From c01b76c4e6d0d58741c2f0f368a4d602a98ff331 Mon Sep 17 00:00:00 2001 From: Omar Ahmad Date: Fri, 30 Aug 2024 13:03:12 +0100 Subject: [PATCH] [NOID] Fixing github action builds to be able to download docker images and maven dependencies from correct places depending on branch --- .../actions/test-gradle-project/action.yml | 4 +- .github/workflows/CI.yaml | 60 +++++++++++++++---- build.gradle | 4 +- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/.github/actions/test-gradle-project/action.yml b/.github/actions/test-gradle-project/action.yml index a3c07531f5..15d3e1695e 100644 --- a/.github/actions/test-gradle-project/action.yml +++ b/.github/actions/test-gradle-project/action.yml @@ -12,10 +12,10 @@ runs: - uses: ./.github/actions/setup-gradle-cache - name: Run compile tests shell: bash - run: ./gradlew --info -Pneo4jVersionOverride=$NEO4J_VERSION_CI :${{inputs.project-name}}:compileJava :${{inputs.project-name}}:compileTestJava + run: ./gradlew --info -Pneo4jVersionOverride=$NEO4JVERSION -Pneo4jDockerEeOverride=$NEO4J_ENTERPRISE_IMAGE -Pneo4jDockerCeOverride=$NEO4J_COMMUNITY_IMAGE :${{inputs.project-name}}:compileJava :${{inputs.project-name}}:compileTestJava - name: Run tests shell: bash - run: ./gradlew --info -Pneo4jVersionOverride=$NEO4J_VERSION_CI :${{inputs.project-name}}:check --parallel + run: ./gradlew --info -Pneo4jVersionOverride=$NEO4JVERSION -Pneo4jDockerEeOverride=$NEO4J_ENTERPRISE_IMAGE -Pneo4jDockerCeOverride=$NEO4J_COMMUNITY_IMAGE :${{inputs.project-name}}:check --parallel - name: Archive test results uses: actions/upload-artifact@v2 if: always() diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 2e0fe4b2e0..bf12411d74 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -7,8 +7,10 @@ on: branches: [ "dev" ] env: - CODEARTIFACT_DOWNLOAD_URL: ${{ secrets.CODEARTIFACT_DOWNLOAD_URL }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + CODEARTIFACT_URL: ${{ secrets.CODEARTIFACT_URL }} CODEARTIFACT_USERNAME: ${{ secrets.CODEARTIFACT_USERNAME }} + ECR_NEO4J_DOCKER_URL: ${{ secrets.ECR_NEO4J_DOCKER_URL }} jobs: @@ -40,18 +42,26 @@ jobs: - uses: ./.github/actions/setup-jdk - uses: ./.github/actions/setup-gradle-cache - - name: Determine latest neo4j CI version + - name: Determine Remote Maven Repository, Neo4j Version and Neo4j Docker Images run: | neo4j_version_base=$(grep -e "neo4jVersion = .*" build.gradle | cut -d '=' -f 2 | tr -d \'\" | tr -d ' ') echo "neo4j_version_base=$neo4j_version_base" - NEO4J_VERSION_CI=`aws codeartifact list-package-versions --domain build-service-live --domain-owner ${{ secrets.AWS_ACCOUNT_ID }} --repository ci-live --format maven --namespace org.neo4j --package neo4j --sort-by PUBLISHED_TIME --query "versions[?starts_with(version,'$neo4j_version_base')] | [0].version" | tr -d '" '` - echo "NEO4J_VERSION_CI=$NEO4J_VERSION_CI" >> "$GITHUB_ENV" - echo "Found NEO4j_VERSION_CI=$NEO4J_VERSION_CI" + echo "Analyzing current branch BRANCH_NAME=$BRANCH_NAME" + if [[ $BRANCH_NAME =~ ^5.[0-9]+$ ]]; then + NEO4JVERSION="$neo4j_version_base" + else + NEO4JVERSION="$neo4j_version_base-SNAPSHOT" + CODEARTIFACT_DOWNLOAD_URL="$CODEARTIFACT_URL/ci-live" + echo "CODEARTIFACT_DOWNLOAD_URL=$CODEARTIFACT_DOWNLOAD_URL" + echo "CODEARTIFACT_DOWNLOAD_URL=$CODEARTIFACT_DOWNLOAD_URL" >> "$GITHUB_ENV" + fi + echo "NEO4JVERSION=$NEO4JVERSION" + echo "NEO4JVERSION=$NEO4JVERSION" >> "$GITHUB_ENV" - name: Compile Java run: | chmod +x gradlew - ./gradlew --no-daemon --info -Pneo4jVersionOverride=$NEO4J_VERSION_CI --init-script init.gradle clean + ./gradlew --no-daemon --info -Pneo4jVersionOverride=$NEO4JVERSION --init-script init.gradle clean # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 @@ -59,7 +69,7 @@ jobs: languages: ${{ matrix.language }} - name: Compile - run: ./gradlew --info -Pneo4jVersionOverride=$NEO4J_VERSION_CI compileJava compileTestJava + run: ./gradlew --info -Pneo4jVersionOverride=$NEO4JVERSION compileJava compileTestJava - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 @@ -99,18 +109,44 @@ jobs: ~/.gradle/wrapper key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - - name: Determine latest neo4j CI version + - name: Determine Remote Maven Repository, Neo4j Version and Neo4j Docker Images run: | neo4j_version_base=$(grep -e "neo4jVersion = .*" build.gradle | cut -d '=' -f 2 | tr -d \'\" | tr -d ' ') echo "neo4j_version_base=$neo4j_version_base" - NEO4J_VERSION_CI=`aws codeartifact list-package-versions --domain build-service-live --domain-owner ${{ secrets.AWS_ACCOUNT_ID }} --repository ci-live --format maven --namespace org.neo4j --package neo4j --sort-by PUBLISHED_TIME --query "versions[?starts_with(version,'$neo4j_version_base')] | [0].version" | tr -d '" '` - echo "NEO4J_VERSION_CI=$NEO4J_VERSION_CI" >> "$GITHUB_ENV" - echo "Found NEO4j_VERSION_CI=$NEO4J_VERSION_CI" + echo "Analyzing current branch BRANCH_NAME=$BRANCH_NAME" + if [[ $BRANCH_NAME =~ ^5.[0-9]+$ ]]; then + NEO4JVERSION="$neo4j_version_base" + NEO4J_ENTERPRISE_IMAGE="neo4j:$NEO4JVERSION-enterprise" + NEO4J_COMMUNITY_IMAGE="neo4j:$NEO4JVERSION-community" + echo "DOCKER_REMOTE=Dockerhub" >> "$GITHUB_ENV" + else + NEO4JVERSION="$neo4j_version_base-SNAPSHOT" + NEO4J_ENTERPRISE_IMAGE="${{ secrets.ECR_NEO4J_DOCKER_URL }}/build-service/neo4j:$neo4j_version_base-enterprise-debian-nightly" + NEO4J_COMMUNITY_IMAGE="${{ secrets.ECR_NEO4J_DOCKER_URL }}/build-service/neo4j:$neo4j_version_base-community-debian-nightly" + echo "DOCKER_REMOTE=ECR" >> "$GITHUB_ENV" + CODEARTIFACT_DOWNLOAD_URL="$CODEARTIFACT_URL/ci-live" + echo "CODEARTIFACT_DOWNLOAD_URL=$CODEARTIFACT_DOWNLOAD_URL" + echo "CODEARTIFACT_DOWNLOAD_URL=$CODEARTIFACT_DOWNLOAD_URL" >> "$GITHUB_ENV" + fi + echo "NEO4JVERSION=$NEO4JVERSION" + echo "NEO4JVERSION=$NEO4JVERSION" >> "$GITHUB_ENV" + echo "NEO4J_ENTERPRISE_IMAGE=$NEO4J_ENTERPRISE_IMAGE" + echo "NEO4J_ENTERPRISE_IMAGE=$NEO4J_ENTERPRISE_IMAGE" >> "$GITHUB_ENV" + echo "NEO4J_COMMUNITY_IMAGE=$NEO4J_COMMUNITY_IMAGE" + echo "NEO4J_COMMUNITY_IMAGE=$NEO4J_COMMUNITY_IMAGE" >> "$GITHUB_ENV" + + - name: Login to ECR + if: env.DOCKER_REMOTE == 'ECR' + uses: docker/login-action@v3 + with: + registry: ${{ secrets.ECR_NEO4J_DOCKER_URL }} + username: ${{ secrets.AWS_ACCESS_KEY_ID }} + password: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - name: Init gradle run: | chmod +x gradlew - ./gradlew --info -Pneo4jVersionOverride=$NEO4J_VERSION_CI --init-script init.gradle + ./gradlew --info -Pneo4jVersionOverride=$NEO4JVERSION --init-script init.gradle - name: Run ${{ matrix.project }} tests uses: ./.github/actions/test-gradle-project diff --git a/build.gradle b/build.gradle index 5331ec2239..e2c750d55c 100644 --- a/build.gradle +++ b/build.gradle @@ -91,8 +91,8 @@ subprojects { // neo4jDockerImage system property is used in TestContainerUtil systemProperties 'user.language' : 'en' , 'user.country' : 'US', - 'neo4jDockerImage' : System.getProperty("NEO4JVERSION") ? 'neo4j:' + System.getProperty("NEO4JVERSION") + '-enterprise-debian' : 'neo4j:5.23.0-enterprise', - 'neo4jCommunityDockerImage': System.getProperty("NEO4JVERSION") ? 'neo4j:' + System.getProperty("NEO4JVERSION") + '-debian' : 'neo4j:5.23.0', + 'neo4jDockerImage': project.hasProperty("neo4jDockerEeOverride") ? project.getProperty("neo4jDockerEeOverride") : 'neo4j:5.23.0-enterprise-debian', + 'neo4jCommunityDockerImage': project.hasProperty("neo4jDockerCeOverride") ? project.getProperty("neo4jDockerCeOverride") : 'neo4j:5.23.0-debian', 'coreDir': 'apoc-core/core', 'testDockerBundle': false