diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d1348b6b..c0a6beb7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,12 @@ name: Run tests & Publish to Docker Registry -on: [push, pull_request] +on: + push: + pull_request: + types: [ 'opened' ] jobs: - build: + test: runs-on: ubuntu-latest strategy: max-parallel: 4 @@ -93,17 +96,35 @@ jobs: name: code-coverage-report path: htmlcov - - name: Publish to Docker Registry - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - uses: docker/build-push-action@v1 + 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: 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 }} + + # 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 - if: github.event_name == 'push' && github.ref == 'refs/heads/master' uses: getsentry/action-release@v1 env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} @@ -111,9 +132,16 @@ 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 }} 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 }}