From 29db863fcc9683b82cfdd9a50a55fe21dc982008 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Wed, 30 Oct 2024 10:11:16 +0000
Subject: [PATCH] Workflows: reuse test.yml in release.yml

---
 .github/workflows/release.yml |  128 ++++--------------------------------------
 1 files changed, 12 insertions(+), 116 deletions(-)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index d3df9ce..b69d864 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -5,134 +5,30 @@
 
 name: Release
 
+permissions: {}
+
 jobs:
   build:
-    name: Build
-    runs-on: ubuntu-latest
-    steps:
-      - id: checkout
-        name: Checkout code
-        uses: actions/checkout@v3
-
-      - id: java
-        name: Install Java and Maven
-        uses: actions/setup-java@v2
-        with:
-          distribution: zulu
-          java-version: 11
-
-      - id: vars
-        name: Get project variables
-        run: |
-          echo -n "::set-output name=keycloakVersion::"
-          mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
-          echo -n "::set-output name=artifactId::"
-          mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
-          echo -n "::set-output name=projectName::"
-          mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z :,.-]+$'
-          echo -n "::set-output name=projectVersion::"
-          mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
-
-      - name: Build project
-        run: |
-          mvn -B test package
-
-      - name: Upload artifact
-        uses: actions/upload-artifact@v3
-        with:
-          name: jar
-          path: target/${{ steps.vars.outputs.artifactId }}-${{ steps.vars.outputs.projectVersion }}.jar
-          if-no-files-found: error
-
-    outputs:
-      artifact_id: ${{ steps.vars.outputs.artifactId }}
-      keycloak_version: ${{ steps.vars.outputs.keycloakVersion }}
-      project_name: ${{ steps.vars.outputs.projectName }}
-      project_version: ${{ steps.vars.outputs.projectVersion }}
-
-  test:
-    name: Test
-    runs-on: ubuntu-latest
-    needs: build
-    steps:
-      - id: checkout
-        name: Checkout code
-        uses: actions/checkout@v2
-
-      - id: download_artifact
-        name: Download artifact
-        uses: actions/download-artifact@v3
-        with:
-          name: jar
-
-      - id: create_container
-        name: Create Keycloak container
-        run: |
-          docker run -i -t -d -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -p 8080:8080 --name keycloak "quay.io/keycloak/keycloak:${{ needs.build.outputs.keycloak_version }}" start-dev
-
-      - id: deploy
-        name: Deploy artifact
-        run: |
-          CONTAINER="keycloak"
-          NAME="${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar"
-          FILE="/opt/keycloak/providers/${NAME}"
-          docker cp "${NAME}" "${CONTAINER}:${FILE}"
-          docker restart "${CONTAINER}"
-          for i in {1..60}; do
-            if curl --silent --max-time 1 -o /dev/null http://localhost:8080; then
-                echo && echo "Deployment succeeded!" && exit 0
-            else
-                sleep 1
-                echo -n "."
-            fi
-          done
-          echo && echo "Deployment timeout!" && exit 1
-
-      - id: configure_keycloak
-        name: Configure Keycloak
-        run: |
-          CONTAINER="keycloak"
-          docker exec -i "${CONTAINER}" /bin/bash <<EOF
-            /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
-            /opt/keycloak/bin/kcadm.sh create clients -r master -s clientId=test -s protocol=cas -s enabled=true -s publicClient=true \
-              -s 'redirectUris=["http://localhost/*"]' -s baseUrl=http://localhost -s adminUrl=http://localhost
-            /opt/keycloak/bin/kcadm.sh get serverinfo -r master --fields "providers(login-protocol(providers(cas)))" | grep cas
-          EOF
-
-      - id: run_tests
-        name: Run tests
-        run: |
-          integrationTest/suite.sh
+    uses: ./.github/workflows/test.yml
 
   release:
     name: Release
     runs-on: ubuntu-latest
-    needs: [build, test]
+    needs: [build]
+    permissions:
+      contents: write
     steps:
       - id: download_artifact
         name: Download artifact
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: jar
 
       - id: create_release
         name: Create release
-        uses: actions/create-release@v1
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        uses: softprops/action-gh-release@v2
         with:
-          tag_name: ${{ github.ref }}
-          release_name: ${{ needs.build.outputs.project_name }} ${{ needs.build.outputs.project_version }}
-          draft: false
-          prerelease: false
-
-      - id: upload_release
-        name: Upload release artifact
-        uses: actions/upload-release-asset@v1
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        with:
-          upload_url: ${{ steps.create_release.outputs.upload_url }}
-          asset_path: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
-          asset_name: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
-          asset_content_type: application/java-archive
+          name: ${{ needs.build.outputs.project_name }} ${{ needs.build.outputs.project_version }}
+          files: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
+          fail_on_unmatched_files: true
+          generate_release_notes: true

--
Gitblit v1.9.1