mirror of https://github.com/jacekkow/keycloak-protocol-cas

Jacek Kowalski
7 days ago d473ba5989dc1c6d2677388ba3b592fbaa5751f0
commit | author | age
fd0b0f 1 on:
JK 2   pull_request:
305397 3   workflow_call:
JK 4     outputs:
5       artifact_id:
d473ba 6         value: ${{ jobs.build.outputs.artifact_id }}
305397 7       keycloak_version:
d473ba 8         value: ${{ jobs.build.outputs.keycloak_version }}
305397 9       project_name:
d473ba 10         value: ${{ jobs.build.outputs.project_name }}
305397 11       project_version:
d473ba 12         value: ${{ jobs.build.outputs.project_version }}
fd0b0f 13
JK 14 name: Test
15
b1c0c9 16 permissions: {}
JK 17
fd0b0f 18 jobs:
JK 19   build:
20     name: Build
21     runs-on: ubuntu-latest
22     steps:
23       - id: checkout
24         name: Checkout code
42da5e 25         uses: actions/checkout@v4
fd0b0f 26
de93e7 27       - id: java
JK 28         name: Install Java and Maven
42da5e 29         uses: actions/setup-java@v4
fd0b0f 30         with:
de93e7 31           distribution: zulu
fdb9f6 32           java-version: 17
fd0b0f 33
JK 34       - id: vars
35         name: Get project variables
36         run: |
e6afd1 37           echo -n "keycloakVersion=" >> $GITHUB_OUTPUT
JK 38           mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
39           echo -n "artifactId=" >> $GITHUB_OUTPUT
40           mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
41           echo -n "projectName=" >> $GITHUB_OUTPUT
42           mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z :,.-]+$' >> $GITHUB_OUTPUT
43           echo -n "projectVersion=" >> $GITHUB_OUTPUT
44           mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
fd0b0f 45
JK 46       - name: Build project
47         run: |
48           mvn -B test package
49
50       - name: Upload artifact
42da5e 51         uses: actions/upload-artifact@v4
fd0b0f 52         with:
JK 53           name: jar
54           path: target/${{ steps.vars.outputs.artifactId }}-${{ steps.vars.outputs.projectVersion }}.jar
de93e7 55           if-no-files-found: error
fd0b0f 56
JK 57     outputs:
58       artifact_id: ${{ steps.vars.outputs.artifactId }}
59       keycloak_version: ${{ steps.vars.outputs.keycloakVersion }}
60       project_name: ${{ steps.vars.outputs.projectName }}
61       project_version: ${{ steps.vars.outputs.projectVersion }}
62
63   test:
64     name: Test
65     runs-on: ubuntu-latest
66     needs: build
67     steps:
68       - id: checkout
69         name: Checkout code
42da5e 70         uses: actions/checkout@v4
fd0b0f 71
JK 72       - id: download_artifact
73         name: Download artifact
42da5e 74         uses: actions/download-artifact@v4
fd0b0f 75         with:
JK 76           name: jar
de93e7 77
JK 78       - id: create_container
79         name: Create Keycloak container
80         run: |
81           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
fd0b0f 82
JK 83       - id: deploy
84         name: Deploy artifact
85         run: |
de93e7 86           CONTAINER="keycloak"
fd0b0f 87           NAME="${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar"
de93e7 88           FILE="/opt/keycloak/providers/${NAME}"
JK 89           docker cp "${NAME}" "${CONTAINER}:${FILE}"
90           docker restart "${CONTAINER}"
91           for i in {1..60}; do
92             if curl --silent --max-time 1 -o /dev/null http://localhost:8080; then
93                 echo && echo "Deployment succeeded!" && exit 0
94             else
95                 sleep 1
96                 echo -n "."
97             fi
98           done
99           echo && echo "Deployment timeout!" && exit 1
fd0b0f 100
JK 101       - id: configure_keycloak
102         name: Configure Keycloak
103         run: |
de93e7 104           CONTAINER="keycloak"
fd0b0f 105           docker exec -i "${CONTAINER}" /bin/bash <<EOF
de93e7 106             /opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
JK 107             /opt/keycloak/bin/kcadm.sh create clients -r master -s clientId=test -s protocol=cas -s enabled=true -s publicClient=true \
fd0b0f 108               -s 'redirectUris=["http://localhost/*"]' -s baseUrl=http://localhost -s adminUrl=http://localhost
de93e7 109             /opt/keycloak/bin/kcadm.sh get serverinfo -r master --fields "providers(login-protocol(providers(cas)))" | grep cas
fd0b0f 110           EOF
JK 111
112       - id: run_tests
113         name: Run tests
114         run: |
115           integrationTest/suite.sh