From 9fa09e20e10ed45ec0a59cdcc4484223d4eb9391 Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Thu, 28 Jan 2021 12:09:14 +0100 Subject: Split PR and CI/CD builds --- .github/workflows/ci-cd.yml | 87 +++++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 89 ------------------------------------------ .github/workflows/pr-build.yml | 32 +++++++++++++++ 3 files changed, 119 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/ci-cd.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pr-build.yml (limited to '.github/workflows') diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000..24f170c6 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,87 @@ +name: ci-cd + +on: + push: + branches: [ main ] + +env: + DOCKERHUB_USER: hildan + DOCKER_IMAGE_NAME: seven-wonders-server + DOCKER_IMAGE_TAG_SHA: sha-${{ github.sha }} + DOCKER_IMAGE_TAG_BUILD: build-${{ github.run_id }} + HEROKU_APP_NAME: seven-wonders-online + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 15 + uses: actions/setup-java@v1.4.3 + with: + java-version: 15 + + - name: Gradle build cache + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-build-${{ hashFiles('**/*.gradle*') }} + restore-keys: ${{ runner.os }}-gradle-build- + + - name: Gradle wrapper cache + uses: actions/cache@v2 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }} + + - name: Build with Gradle + run: ./gradlew build + + # technically optional, brings support for more platform to Docker Buildx + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + # required for Docker build/push + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ env.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} + + - name: Login to Heroku Container Registry + uses: docker/login-action@v1 + with: + registry: registry.heroku.com + username: ${{ secrets.HEROKU_EMAIL }} + password: ${{ secrets.HEROKU_API_KEY }} + + - name: Build and push to DockerHub and GitHub Container Registry + uses: docker/build-push-action@v2 + with: + context: ./sw-server + file: ./sw-server/Dockerfile + push: true + tags: | + ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:latest + ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_SHA }} + ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_BUILD }} + ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest + ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_SHA }} + ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_BUILD }} + registry.heroku.com/${{ env.HEROKU_APP_NAME }}/web + + - name: Heroku release (deploy Docker image) + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: heroku container:release -a ${{ env.HEROKU_APP_NAME }} web diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 88f9f05f..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,89 +0,0 @@ -name: CI Build - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -env: - DOCKERHUB_USER: hildan - DOCKER_IMAGE_NAME: seven-wonders-server - DOCKER_IMAGE_TAG_SHA: sha-${{ github.sha }} - DOCKER_IMAGE_TAG_BUILD: build-${{ github.run_id }} - HEROKU_APP_NAME: seven-wonders-online - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 15 - uses: actions/setup-java@v1.4.3 - with: - java-version: 15 - - - name: Gradle build cache - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-build-${{ hashFiles('**/*.gradle*') }} - restore-keys: ${{ runner.os }}-gradle-build- - - - name: Gradle wrapper cache - uses: actions/cache@v2 - with: - path: ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }} - - - name: Build with Gradle - run: ./gradlew build - - # technically optional, brings support for more platform to Docker Buildx - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - # required for Docker build/push - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ env.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} - - - name: Login to Heroku Container Registry - uses: docker/login-action@v1 - with: - registry: registry.heroku.com - username: ${{ secrets.HEROKU_EMAIL }} - password: ${{ secrets.HEROKU_API_KEY }} - - - name: Build and push to DockerHub and GitHub Container Registry - uses: docker/build-push-action@v2 - with: - context: ./sw-server - file: ./sw-server/Dockerfile - push: true - tags: | - ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:latest - ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_SHA }} - ${{ env.DOCKERHUB_USER }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_BUILD }} - ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest - ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_SHA }} - ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG_BUILD }} - registry.heroku.com/${{ env.HEROKU_APP_NAME }}/web - - - name: Heroku release (deploy Docker image) - env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:release -a ${{ env.HEROKU_APP_NAME }} web diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml new file mode 100644 index 00000000..67a9c9be --- /dev/null +++ b/.github/workflows/pr-build.yml @@ -0,0 +1,32 @@ +name: pr-build + +on: + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 15 + uses: actions/setup-java@v1.4.3 + with: + java-version: 15 + + - name: Gradle build cache + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-build-${{ hashFiles('**/*.gradle*') }} + restore-keys: ${{ runner.os }}-gradle-build- + + - name: Gradle wrapper cache + uses: actions/cache@v2 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }} + + - name: Build with Gradle + run: ./gradlew build -- cgit