From d2943cfc8838a49c4012a6e4b9fc2000d526b2bb Mon Sep 17 00:00:00 2001 From: Matias Schilling Date: Thu, 23 Nov 2023 22:25:56 +0900 Subject: [PATCH] Use GitHub actions for build --- .circleci/config.yml | 154 ---------------------------------- .github/workflows/release.yml | 55 ++++++++++++ build.gradle | 1 - 3 files changed, 55 insertions(+), 155 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/release.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 62c655c..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,154 +0,0 @@ ---- -version: 2 - -jobs: - build: - environment: - # Configure the JVM and Gradle to avoid OOM errors - _JAVA_OPTIONS: "-Xmx3g" - GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2" - docker: - - image: circleci/openjdk:11.0.3-jdk-stretch - steps: - - checkout - - restore_cache: - key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - - restore_cache: - key: v1-gradle-cache-{{ checksum "build.gradle" }} - - run: - name: Install dependencies - command: ./gradlew build -x test - - save_cache: - paths: - - ~/.gradle/wrapper - key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - - save_cache: - paths: - - ~/.gradle/caches - key: v1-gradle-cache-{{ checksum "build.gradle" }} - - persist_to_workspace: - root: . - paths: - - build - - release-production: - docker: - - image: circleci/openjdk:11.0.3-jdk-stretch - steps: - - checkout - - attach_workspace: - at: . - - setup_remote_docker - - run: - name: Log into docker registry - command: | - docker login --username=_ --password=${HEROKU_REGISTRY_TOKEN} registry.heroku.com - - run: - name: Build and push image - command: | - ./gradlew clean dockerTagHerokuProduction - docker push registry.heroku.com/chucky/web - - run: - name: Release - command: | - export IMAGE_ID=$(docker inspect registry.heroku.com/chucky/web --format={{.Id}}) - curl -X PATCH \ - https://api.heroku.com/apps/chucky/formation \ - -H 'Accept: application/vnd.heroku+json; version=3.docker-releases' \ - -H "Authorization: Bearer ${HEROKU_REGISTRY_TOKEN}" \ - -H 'Content-Type: application/json' \ - -d "{\"updates\":[{\"type\":\"web\",\"docker_image\":\"${IMAGE_ID}\"}]}" - - run: - name: Remove docker credentials - command: | - rm "${HOME}/.docker/config.json" - - release-staging: - docker: - - image: circleci/openjdk:11.0.3-jdk-stretch - steps: - - checkout - - attach_workspace: - at: . - - setup_remote_docker - - run: - name: Log into docker registry - command: | - docker login --username=_ --password=${HEROKU_REGISTRY_TOKEN} registry.heroku.com - - run: - name: Build and push image - command: | - ./gradlew clean dockerTagHerokuStaging - docker push registry.heroku.com/chucky-staging/web - - run: - name: Release - command: | - export IMAGE_ID=$(docker inspect registry.heroku.com/chucky-staging/web --format={{.Id}}) - curl -X PATCH \ - https://api.heroku.com/apps/chucky-staging/formation \ - -H 'Accept: application/vnd.heroku+json; version=3.docker-releases' \ - -H "Authorization: Bearer ${HEROKU_REGISTRY_TOKEN}" \ - -H 'Content-Type: application/json' \ - -d "{\"updates\":[{\"type\":\"web\",\"docker_image\":\"${IMAGE_ID}\"}]}" - - run: - name: Remove docker credentials - command: | - rm "${HOME}/.docker/config.json" - - test-unit: - docker: - - image: circleci/openjdk:11.0.3-jdk-stretch - steps: - - checkout - - attach_workspace: - at: . - - run: - name: Run unit test - command: ./gradlew test - -workflows: - version: 2 - - test_and_release_staging: - jobs: - - build: - filters: - branches: - ignore: master - - test-unit: - requires: - - build - filters: - branches: - ignore: master - - release-staging: - requires: - - test-unit - filters: - branches: - ignore: master - - test_and_release_production: - jobs: - - build: - filters: - branches: - only: master - - test-unit: - requires: - - build - filters: - branches: - only: master - - release-staging: - requires: - - test-unit - filters: - branches: - only: master - - release-production: - requires: - - release-staging - filters: - branches: - only: master \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a60834b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +# GitHub Actions documentation +# => https://docs.github.com/en/actions +name: Release + +on: + push: + branches: + - master + +jobs: + + unit-test: + if: "!contains(github.event.head_commit.message, 'skip-ci')" + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + cache: 'gradle' + - run: | + ./gradlew test + + release: + if: "!contains(github.event.head_commit.message, 'skip-ci')" + needs: [ unit-test ] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + cache: 'gradle' + - name: Login to Heroku Docker Registry + uses: docker/login-action@v1 + with: + password: ${{ secrets.HEROKU_REGISTRY_TOKEN }} + registry: registry.heroku.com + username: _ + - name: 'Push image to Heroku registry' + run: ./gradlew dockerPushHerokuProduction + - name: Trigger release + shell: bash + env: + HEROKU_REGISTRY_TOKEN: ${{ secrets.HEROKU_REGISTRY_TOKEN }} + run: | + export IMAGE_ID=$(docker inspect registry.heroku.com/chucky/web --format={{.Id}}) + curl -X PATCH \ + https://api.heroku.com/apps/chucky/formation \ + -H 'Accept: application/vnd.heroku+json; version=3.docker-releases' \ + -H "Authorization: Bearer ${HEROKU_REGISTRY_TOKEN}" \ + -H 'Content-Type: application/json' \ + -d "{\"updates\":[{\"type\":\"web\",\"docker_image\":\"${IMAGE_ID}\"}]}" diff --git a/build.gradle b/build.gradle index f038d43..efa7b76 100644 --- a/build.gradle +++ b/build.gradle @@ -74,7 +74,6 @@ tasks { tag("current", "${imageName}:${appVer}") tag("latest", "${imageName}:latest") tag("herokuProduction", "registry.heroku.com/chucky/web") - tag("herokuStaging", "registry.heroku.com/chucky-staging/web") dockerfile file("${projectDir}/src/main/docker/Dockerfile") files tasks.bootJar.outputs