From 60cf9d18377e782f4494225dc7df31f2e7c02ca8 Mon Sep 17 00:00:00 2001 From: broknloop <90255202+broknloop@users.noreply.github.com> Date: Thu, 9 Nov 2023 04:30:53 +0100 Subject: [PATCH] Workflow multiple steps (#37) * Create maven.yml * Update maven.yml * Try full workflow * Try to break into different steps --------- Co-authored-by: Broknloop --- .github/workflows/merge.yaml | 47 +++++++++++++++++++++++++ .github/workflows/pr.yaml | 33 ++++++++++++++++++ .github/workflows/push-image.yaml | 57 +++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 .github/workflows/merge.yaml create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/push-image.yaml diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml new file mode 100644 index 0000000..831769c --- /dev/null +++ b/.github/workflows/merge.yaml @@ -0,0 +1,47 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + pull_request: + types: + - closed + branches: + - master + +jobs: + build: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: '0' + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'corretto' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + + - name: Bump version and push tag + uses: anothrNick/github-tag-action@1.64.0 # Don't use @master or @v1 unless you're happy to test the latest version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token + WITH_V: true diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..50a25ff --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,33 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: '0' + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'corretto' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/.github/workflows/push-image.yaml b/.github/workflows/push-image.yaml new file mode 100644 index 0000000..971124c --- /dev/null +++ b/.github/workflows/push-image.yaml @@ -0,0 +1,57 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Push image +on: + push: + tags: + - 'v*' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + vispana/vispana + docker.io/vispana/vispana + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + flavor: | + latest=true + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64/v8 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}