From 3586d811286f0bd54a91df10e763035afb5dc347 Mon Sep 17 00:00:00 2001 From: Tobias Meindl Date: Tue, 30 Apr 2024 14:09:04 +0200 Subject: [PATCH] add the new build workflow --- .github/workflows/main.yaml | 50 +++++++++++++++---------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2494ae03c..038afc811 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,6 +1,9 @@ name: Release Containerimage on: + push: + branches: + - main workflow_dispatch: jobs: @@ -10,47 +13,34 @@ jobs: - uses: actions/checkout@v3 name: checkout - - name: Cache the Maven packages to speed up build - uses: actions/cache@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + java-version: '17' + distribution: 'temurin' + cache: maven - - name: Build and test project with Maven - run: mvn -B package -D skipTests --file pom.xml + - name: Build (and test) project with Maven + run: mvn -B package --file pom.xml + # set the env.BRANCH_NAME variable - uses: nelonoel/branch-name@v1.0.1 - name: Set outputs id: vars run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - uses: mr-smithers-excellent/docker-build-push@v5 + # set the env.COMMIT variable + - run: echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + # build the container image and release it as a package in this repository + - uses: mr-smithers-excellent/docker-build-push@v6 name: push-container-image with: image: mega-backend registry: ghcr.io - username: ${{ github.repository }} - password: ${{ secrets.GHCR_TOKEN }} dockerfile: Containerfile - addLatest: true - tags: ${{ steps.vars.outputs.sha_short }},latest - buildArgs: BRANCH=${BRANCH_NAME},COMMIT=${{ steps.vars.outputs.sha_short }},VERSION=${{ steps.vars.outputs.sha_short }} - -# notify: -# name: Slack Notifications -# runs-on: ubuntu-latest -# if: ${{ failure() }} -# needs: -# - build-and-test -# - docker-build-and-push -# steps: -# - name: Notify Slack channel on failure -# uses: rtCamp/action-slack-notify@v2 -# env: -# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} -# SLACK_ICON: https://avatars.githubusercontent.com/u/74975412?s=200&v=4 -# SLACK_USERNAME: ${{ github.repository }} -# SLACK_COLOR: '#ff0033' -# SLACK_FOOTER: '' \ No newline at end of file + buildArgs: COMMIT=${{ env.COMMIT}}, BRANCH=${{ env.BRANCH_NAME}}, VERSION=${{ env.COMMIT}} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + addLatest: ${{ github.ref == 'refs/heads/main' }} \ No newline at end of file