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

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