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

github-actions
2022-06-25 67a13c292b95e985e4d2bc3531d56ad8599682f3
commit | author | age
fd0b0f 1 on:
JK 2   push:
3     tags:
4       - '[0-9]+.*'
5
6 name: Release
7
8 jobs:
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
19         uses: actions/setup-java@v2
fd0b0f 20         with:
de93e7 21           distribution: zulu
JK 22           java-version: 11
fd0b0f 23
JK 24       - id: vars
25         name: Get project variables
26         run: |
27           echo -n "::set-output name=keycloakVersion::"
4da0d9 28           mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
fd0b0f 29           echo -n "::set-output name=artifactId::"
4da0d9 30           mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
fd0b0f 31           echo -n "::set-output name=projectName::"
4da0d9 32           mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z :,.-]+$'
fd0b0f 33           echo -n "::set-output name=projectVersion::"
4da0d9 34           mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$'
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
60         uses: actions/checkout@v2
61
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
106
107   release:
108     name: Release
109     runs-on: ubuntu-latest
110     needs: [build, test]
111     steps:
112       - id: download_artifact
113         name: Download artifact
de93e7 114         uses: actions/download-artifact@v3
fd0b0f 115         with:
JK 116           name: jar
117
118       - id: create_release
119         name: Create release
120         uses: actions/create-release@v1
121         env:
122           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123         with:
124           tag_name: ${{ github.ref }}
125           release_name: ${{ needs.build.outputs.project_name }} ${{ needs.build.outputs.project_version }}
126           draft: false
127           prerelease: false
128
129       - id: upload_release
130         name: Upload release artifact
131         uses: actions/upload-release-asset@v1
132         env:
133           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134         with:
135           upload_url: ${{ steps.create_release.outputs.upload_url }}
de93e7 136           asset_path: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
fd0b0f 137           asset_name: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
JK 138           asset_content_type: application/java-archive