From 42159dce4d321ea810fc6257f7b92568cd40ffd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Wed, 11 May 2022 16:33:24 +0200 Subject: [PATCH 1/5] Run docker build only once and also on tag --- .github/workflows/main.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d1348b6b..cafd33bb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Run tests & Publish to Docker Registry on: [push, pull_request] jobs: - build: + test: runs-on: ubuntu-latest strategy: max-parallel: 4 @@ -93,8 +93,13 @@ jobs: name: code-coverage-report path: htmlcov + build: + runs-on: ubuntu-latest + needs: ['test'] + + steps: - name: Publish to Docker Registry - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) uses: docker/build-push-action@v1 with: repository: simplelogin/app-ci @@ -103,7 +108,7 @@ jobs: tag_with_ref: true - name: Create Sentry release - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) uses: getsentry/action-release@v1 env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} From 4f8a590ef9a1cecfa534f88dd20f49fdf5ba7a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Wed, 11 May 2022 16:35:08 +0200 Subject: [PATCH 2/5] Run only on pull --- .github/workflows/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cafd33bb..2528638e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,9 @@ name: Run tests & Publish to Docker Registry -on: [push, pull_request] +on: + push: + pull_request: + types: [ 'opened' ] jobs: test: From b3645b33dde9f7a786dbc84df1f3ce15c60b268a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Wed, 11 May 2022 16:48:27 +0200 Subject: [PATCH 3/5] Set global change for the job --- .github/workflows/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2528638e..7ee85fe9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,10 +99,10 @@ jobs: build: runs-on: ubuntu-latest needs: ['test'] + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) steps: - name: Publish to Docker Registry - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) uses: docker/build-push-action@v1 with: repository: simplelogin/app-ci @@ -111,7 +111,6 @@ jobs: tag_with_ref: true - name: Create Sentry release - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) uses: getsentry/action-release@v1 env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} @@ -119,7 +118,6 @@ jobs: SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} - name: Send Telegram message - if: github.event_name == 'push' && github.ref == 'refs/heads/master' uses: appleboy/telegram-action@master with: to: ${{ secrets.TELEGRAM_TO }} From cbcd4ea92fc2990d2f7f5823c813de44f8d12bca Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Thu, 12 May 2022 08:54:44 +0200 Subject: [PATCH 4/5] Add slack message sending + upgrade docker build process --- .github/workflows/main.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7ee85fe9..66bb9d34 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,13 +102,23 @@ jobs: if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) steps: - - name: Publish to Docker Registry - uses: docker/build-push-action@v1 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: simplelogin/app-ci + + - name: Login to Docker Hub + uses: docker/login-action@v2 with: - repository: simplelogin/app-ci username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - tag_with_ref: true + + - name: Build image and publish to Docker Registry + uses: docker/build-push-action@v3 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} - name: Create Sentry release uses: getsentry/action-release@v1 @@ -123,3 +133,11 @@ jobs: to: ${{ secrets.TELEGRAM_TO }} token: ${{ secrets.TELEGRAM_TOKEN }} args: Docker image pushed on ${{ github.ref }} + + - name: Post notification to Slack + uses: slackapi/slack-github-action@v1.19.0 + with: + channel-id: ${{ secrets.SLACK_CHANNEL_ID }} + slack-message: "New tag generated: ${{github.ref}}\nBuild result: ${{ job.status }}" + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} From e01bae6206694f08434490849a663644ac891e62 Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Thu, 12 May 2022 09:12:10 +0200 Subject: [PATCH 5/5] Fix create sentry release --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 66bb9d34..c0a6beb7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -120,6 +120,10 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} + # We need to checkout the repository in order for the "Create Sentry release" to work + - name: Checkout repository + uses: actions/checkout@v2 + - name: Create Sentry release uses: getsentry/action-release@v1 env: