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

github-actions
2023-09-13 e8fed4af98dd55ec4fa3deff106866507a71e404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
on:
  push:
    tags:
      - '[0-9]+.*'
 
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@v3
        with:
          distribution: zulu
          java-version: 17
 
      - id: vars
        name: Get project variables
        run: |
          echo -n "keycloakVersion=" >> $GITHUB_OUTPUT
          mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
          echo -n "artifactId=" >> $GITHUB_OUTPUT
          mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
          echo -n "projectName=" >> $GITHUB_OUTPUT
          mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z :,.-]+$' >> $GITHUB_OUTPUT
          echo -n "projectVersion=" >> $GITHUB_OUTPUT
          mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null | grep -E '^[0-9a-zA-Z.-]+$' >> $GITHUB_OUTPUT
 
      - 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@v3
 
      - 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
 
  release:
    name: Release
    runs-on: ubuntu-latest
    needs: [build, test]
    permissions:
      contents: write
    steps:
      - id: download_artifact
        name: Download artifact
        uses: actions/download-artifact@v3
        with:
          name: jar
 
      - id: create_release
        name: Create release
        uses: softprops/action-gh-release@v1
        with:
          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