diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 68f3674c..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,124 +0,0 @@ -version: 2.1 -aliases: - - &jfrog-login - name: Rename jfrog environment variable for maven setting.xml - command: | - echo "export JFROG_USER=$ARTIFACTORY_USER" >> $BASH_ENV - echo "export JFROG_PASS=$ARTIFACTORY_PASSWORD" >> $BASH_ENV - - &post_build - name: Trigger downstream builds - command: | - wget https://raw.githubusercontent.com/entur/circleci-toolbox-image-java11/master/tools/trigger_build_v2.sh -O .circleci/trigger_build_v2.sh - chmod +x .circleci/trigger_build_v2.sh - echo 'export CIRCLE_SHA1="$CIRCLE_SHA1"' >> $BASH_ENV - echo 'export CIRCLE_PROJECT_REPONAME="$CIRCLE_PROJECT_REPONAME"' >> $BASH_ENV - .circleci/trigger_build_v2.sh "entur/uttu-deployment-config.git" "master" "$(git log -1 --pretty=%B)" - - &tag-git-version - name: Tag git commit with build version and push to github - command: | - VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec) - git config --global user.email "circleci@entur.no" - git config --global user.name "circleci" - git tag v$VERSION-$CIRCLE_BUILD_NUM - git push origin v$VERSION-$CIRCLE_BUILD_NUM - - &sonar-scan - name: Sonar scan - command: | - mvn -s .circleci/settings.xml \ - org.jacoco:jacoco-maven-plugin:prepare-agent verify \ - org.jacoco:jacoco-maven-plugin:report sonar:sonar \ - -P prettierSkip \ - -Dmaven.main.skip \ - -DskipTests \ - -Dsonar.projectKey=entur_${CIRCLE_PROJECT_REPONAME} \ - -Dsonar.organization=${SONAR_ORG} \ - -Dsonar.projectName=${CIRCLE_PROJECT_REPONAME} \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.token=${ENTUR_SONAR_PASSWORD} -jobs: - test: - machine: - image: ubuntu-2204:2024.04.3 - environment: - MAVEN_OPTS: -Xmx3G - steps: - - checkout - - restore_cache: - keys: - - dep-cache-v2-{{ checksum "pom.xml" }} - - dep-cache-v2- - - run: - name: Download Maven settings - command: wget https://raw.githubusercontent.com/entur/circleci-toolbox-image-java11/master/tools/m2/settings.xml -O .circleci/settings.xml - - run: *jfrog-login - - run: - name: Refresh cache - command: mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.0:go-offline -s .circleci/settings.xml - - save_cache: - paths: - - ~/.m2 - key: dep-cache-v2-{{ checksum "pom.xml" }} - # Cannot use -o because of snapshot dependencies. - - run: - name: Run Maven verify - command: mvn verify -s .circleci/settings.xml -Dprettier.nodePath=node -Dprettier.npmPath=npm - - run: *sonar-scan - - run: - name: Save test results - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; - find . -type f -regex ".*/target/surefire-reports/.*dumpstream" -exec cp {} ~/junit/ \; - find . -type f -regex ".*/target/surefire-reports/.*log" -exec cp {} ~/junit/ \; - when: always - - store_test_results: - path: ~/junit - - store_artifacts: - path: ~/junit - - persist_to_workspace: - root: ~/project - paths: - - target - - .circleci - build: - docker: - - image: cimg/openjdk:21.0.2-node - auth: - username: $DOCKERHUB_LOGIN - password: $DOCKERHUB_PASSWORD - environment: - MAVEN_OPTS: -Xmx3G - steps: - - checkout - - restore_cache: - keys: - - dep-cache-v2-{{ checksum "pom.xml" }} - - dep-cache-v2- - - run: - name: Download Maven settings - command: wget https://raw.githubusercontent.com/entur/circleci-toolbox-image-java11/master/tools/m2/settings.xml -O .circleci/settings.xml - - run: *jfrog-login - - run: - name: Refresh cache - command: mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.0:go-offline -s .circleci/settings.xml - - save_cache: - paths: - - ~/.m2 - key: dep-cache-v2-{{ checksum "pom.xml" }} - # Cannot use -o because of snapshot dependencies. - - run: mvn deploy -s .circleci/settings.xml -P prettierSkip -DskipTests - - run: *tag-git-version - - run: *post_build -workflows: - release: - jobs: - - test: - context: global - - build: - context: global - filters: - branches: - only: - - master - requires: - - test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0020bd62..e0c705d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,3 +35,49 @@ jobs: sudo timedatectl set-timezone "Europe/Oslo" mvn --batch-mode jacoco:prepare-agent test jacoco:report -Dprettier.nodePath=node -Dprettier.npmPath=npm mvn --batch-mode jib:dockerBuild -Dmaven.test.skip -P prettierSkip + image: + # only build and push the image when it's a commit to master in Entur's repository + if: github.repository_owner == 'entur' && github.event_name == 'push' + runs-on: ubuntu-latest + needs: [ tests ] + env: + CONTAINER_REPO: docker.io/entur/uttu + CONTAINER_REGISTRY_USER: ${{ secrets.DOCKERHUB_LOGIN }} + CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: temurin + cache: maven + - name: set variables + run: | + echo "GHA_DOCKER_PUSH_IMAGE_TAG=`date +%Y-%m-%dT%H-%M`" >> $GITHUB_ENV + + - name: Build container image with Jib, push to container repo + run: | + mvn --batch-mode compile com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,${{ env.GHA_DOCKER_PUSH_IMAGE_TAG }} -Dmaven.test.skip -P prettierSkip + + - name: Tag default branch with the container image tag ${{ env.GHA_DOCKER_PUSH_IMAGE_TAG }} + id: tag-version + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git tag --annotate "$GHA_DOCKER_PUSH_IMAGE_TAG" -m "chore(tag): $GHA_DOCKER_PUSH_IMAGE_TAG [skip ci]" --force + git push origin "$GHA_DOCKER_PUSH_IMAGE_TAG" --force + + - name: Trigger downstream CI + run: | + repo_owner="entur" + repo_name="uttu-deployment-config" + event_type="trigger-downstream-ci" + service="uttu" + echo "Triggering downstream CI for $service with version ${{ env.GHA_DOCKER_PUSH_IMAGE_TAG }}" + curl -X POST \ + -H "Authorization: token ${{ secrets.GITFLOW_PAT }}" \ + -H "Accept: application/vnd.github.everest-preview+json" \ + -H "Content-Type: application/json" https://api.github.com/repos/$repo_owner/$repo_name/dispatches \ + -d "{\"event_type\": \"$event_type\", \"client_payload\": {\"service\": \"$service\", \"version\": \"$GHA_DOCKER_PUSH_IMAGE_TAG\", \"unit\": false, \"integration\": true}}" \ No newline at end of file diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml deleted file mode 100644 index e21dc42e..00000000 --- a/.github/workflows/image.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: CI Build - -on: - push: - tags: - - 'v*.*.*' -jobs: - tests: - runs-on: ubuntu-latest - env: - TZ: Europe/Oslo - steps: - - uses: actions/checkout@v4 - - # nodejs is needed because the dynamic download of it via the prettier maven plugin often - # times out - # Example: https://github.com/opentripplanner/OpenTripPlanner/actions/runs/4490450225/jobs/7897533439 - - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: temurin - cache: maven - - - name: Run tests - run: | - sudo timedatectl set-timezone "Europe/Oslo" - mvn --batch-mode jacoco:prepare-agent test jacoco:report -Dprettier.nodePath=node -Dprettier.npmPath=npm - mvn --batch-mode jib:dockerBuild -Dmaven.test.skip -P prettierSkip - - - image: - # only build and push the image when it's a commit to master in Entur's repository - if: github.repository_owner == 'entur' && github.event_name == 'push' - runs-on: ubuntu-latest - needs: [ tests ] - env: - CONTAINER_REPO: docker.io/entur/uttu - CONTAINER_REGISTRY_USER: ${{ secrets.DOCKERHUB_LOGIN }} - CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - steps: - - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: temurin - cache: maven - - - name: Build container image with Jib, push to container repo - run: | - mvn --batch-mode compile com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,${{ github.ref_name }} -Dmaven.test.skip -P prettierSkip