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

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