Browse Source

[Infra] A first try of reusable workflows (#3497)

* add resusable action

* fix yaml

* fix yaml

* fix

* fix syntax errors

* fix syntax

* Apply suggestions from code review

Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>

---------

Co-authored-by: Narek Matevosyan <nmatevosyan@provectus.com>
Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
Narekmat 2 years ago
parent
commit
36112fa26b
2 changed files with 34 additions and 15 deletions
  1. 2 15
      .github/workflows/branch-deploy.yml
  2. 32 0
      .github/workflows/build-template.yml

+ 2 - 15
.github/workflows/branch-deploy.yml

@@ -9,9 +9,9 @@ jobs:
     if: ${{ github.event.label.name == 'status/feature_testing' || github.event.label.name == 'status/feature_testing_public' }}
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: ./.github/workflows/build-template.yaml
         with:
-          ref: ${{ github.event.pull_request.head.sha }}
+          APP_VERSION: $GITHUB_SHA
       - name: get branch name
         id: extract_branch
         run: |
@@ -19,19 +19,6 @@ jobs:
           echo "tag=${tag}" >> $GITHUB_OUTPUT
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-      - name: Set up JDK
-        uses: actions/setup-java@v3
-        with:
-          java-version: '17'
-          distribution: 'zulu'
-          cache: 'maven'
-      - name: Build
-        id: build
-        run: |
-          ./mvnw -B -ntp versions:set -DnewVersion=$GITHUB_SHA
-          ./mvnw -B -V -ntp clean package -Pprod -DskipTests
-          export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
-          echo "version=${VERSION}" >> $GITHUB_OUTPUT
       - name: Set up QEMU
         uses: docker/setup-qemu-action@v2
       - name: Set up Docker Buildx

+ 32 - 0
.github/workflows/build-template.yml

@@ -0,0 +1,32 @@
+name: Maven build template
+on:
+  workflow_call:
+   inputs:
+    APP_VERSION:
+     required: true
+     type: string
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    outputs:
+      version: ${{steps.build.outputs.version}}
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+      - run: |
+          git config user.name github-actions
+          git config user.email github-actions@github.com
+      - name: Set up JDK
+        uses: actions/setup-java@v3
+        with:
+          java-version: '17'
+          distribution: 'zulu'
+          cache: 'maven'
+      - name: Build
+        id: build
+        run: |
+          ./mvnw -B -ntp versions:set -DnewVersion=${{ inputs.APP_VERSION }}
+          ./mvnw -B -V -ntp clean package -Pprod -DskipTests
+          export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
+          echo "version=${VERSION}" >> $GITHUB_OUTPUT