From fd0b0f59812335633513d05f08264dddcdc909b7 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Wed, 06 May 2020 00:00:30 +0000
Subject: [PATCH] Replace Travis CI build with GitHub actions

---
 /dev/null                     |   50 --------
 .github/workflows/test.yml    |  109 ++++++++++++++++++
 .github/workflows/release.yml |  144 ++++++++++++++++++++++++
 3 files changed, 253 insertions(+), 50 deletions(-)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..c6bc7a3
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,144 @@
+on:
+  push:
+    tags:
+      - '[0-9]+.*'
+
+name: Release
+
+jobs:
+  build:
+    name: Build
+    runs-on: ubuntu-latest
+    steps:
+      - id: checkout
+        name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Install Java and Maven
+        uses: actions/setup-java@v1
+        with:
+          java-version: 8
+
+      - id: vars
+        name: Get project variables
+        run: |
+          echo -n "::set-output name=keycloakVersion::"
+          mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=artifactId::"
+          mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=projectName::"
+          mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=projectVersion::"
+          mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null
+          echo
+
+      - name: Build project
+        run: |
+          mvn -B test package
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v1
+        with:
+          name: jar
+          path: target/${{ steps.vars.outputs.artifactId }}-${{ steps.vars.outputs.projectVersion }}.jar
+
+    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
+    services:
+      keycloak:
+        image: quay.io/keycloak/keycloak:${{ needs.build.outputs.keycloak_version }}
+        env:
+          KEYCLOAK_USER: admin
+          KEYCLOAK_PASSWORD: admin
+        ports:
+          - 8080:8080
+        volumes:
+          - '${{ github.workspace }}:/workspace'
+    steps:
+      - id: checkout
+        name: Checkout code
+        uses: actions/checkout@v2
+
+      - id: download_artifact
+        name: Download artifact
+        uses: actions/download-artifact@v1
+        with:
+          name: jar
+
+      - id: deploy
+        name: Deploy artifact
+        run: |
+          CONTAINER="${{ job.services.keycloak.id }}"
+          NAME="${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar"
+          FILE="/opt/jboss/keycloak/standalone/deployments/${NAME}"
+          docker cp "jar/${NAME}" "${CONTAINER}:/tmp/"
+          docker exec -i "${CONTAINER}" /bin/bash <<EOF
+            cp "/tmp/${NAME}" "${FILE}"
+            for i in {1..60}; do
+              echo -n .
+              [ -f "${FILE}.deployed" ] && echo && echo "Deployment succeeded!" && exit 0
+              [ -f "${FILE}.failed" ] && echo && echo "Deployment failed!" && exit 1
+              sleep 1
+            done
+            echo && echo "Deployment timeout!" && exit 1
+          EOF
+
+      - id: configure_keycloak
+        name: Configure Keycloak
+        run: |
+          CONTAINER="${{ job.services.keycloak.id }}"
+          docker exec -i "${CONTAINER}" /bin/bash <<EOF
+            /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password admin
+            /opt/jboss/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/jboss/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]
+    steps:
+      - id: download_artifact
+        name: Download artifact
+        uses: actions/download-artifact@v1
+        with:
+          name: jar
+
+      - id: create_release
+        name: Create release
+        uses: actions/create-release@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          tag_name: ${{ github.ref }}
+          release_name: ${{ needs.build.outputs.project_name }} ${{ needs.build.outputs.project_version }}
+          draft: false
+          prerelease: false
+
+      - id: upload_release
+        name: Upload release artifact
+        uses: actions/upload-release-asset@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          upload_url: ${{ steps.create_release.outputs.upload_url }}
+          asset_path: jar/${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
+          asset_name: ${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar
+          asset_content_type: application/java-archive
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..eddd6e7
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,109 @@
+on:
+  pull_request:
+
+name: Test
+
+jobs:
+  build:
+    name: Build
+    runs-on: ubuntu-latest
+    steps:
+      - id: checkout
+        name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Install Java and Maven
+        uses: actions/setup-java@v1
+        with:
+          java-version: 8
+
+      - id: vars
+        name: Get project variables
+        run: |
+          echo -n "::set-output name=keycloakVersion::"
+          mvn -q help:evaluate -Dexpression=keycloak.version -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=artifactId::"
+          mvn -q help:evaluate -Dexpression=project.artifactId -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=projectName::"
+          mvn -q help:evaluate -Dexpression=project.name -DforceStdout 2> /dev/null
+          echo
+          echo -n "::set-output name=projectVersion::"
+          mvn -q help:evaluate -Dexpression=project.version -DforceStdout 2> /dev/null
+          echo
+
+      - name: Build project
+        run: |
+          mvn -B test package
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v1
+        with:
+          name: jar
+          path: target/${{ steps.vars.outputs.artifactId }}-${{ steps.vars.outputs.projectVersion }}.jar
+
+    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
+    services:
+      keycloak:
+        image: quay.io/keycloak/keycloak:${{ needs.build.outputs.keycloak_version }}
+        env:
+          KEYCLOAK_USER: admin
+          KEYCLOAK_PASSWORD: admin
+        ports:
+          - 8080:8080
+        volumes:
+          - '${{ github.workspace }}:/workspace'
+    steps:
+      - id: checkout
+        name: Checkout code
+        uses: actions/checkout@v2
+
+      - id: download_artifact
+        name: Download artifact
+        uses: actions/download-artifact@v1
+        with:
+          name: jar
+
+      - id: deploy
+        name: Deploy artifact
+        run: |
+          CONTAINER="${{ job.services.keycloak.id }}"
+          NAME="${{ needs.build.outputs.artifact_id }}-${{ needs.build.outputs.project_version }}.jar"
+          FILE="/opt/jboss/keycloak/standalone/deployments/${NAME}"
+          docker cp "jar/${NAME}" "${CONTAINER}:/tmp/"
+          docker exec -i "${CONTAINER}" /bin/bash <<EOF
+            cp "/tmp/${NAME}" "${FILE}"
+            for i in {1..60}; do
+              echo -n .
+              [ -f "${FILE}.deployed" ] && echo && echo "Deployment succeeded!" && exit 0
+              [ -f "${FILE}.failed" ] && echo && echo "Deployment failed!" && exit 1
+              sleep 1
+            done
+            echo && echo "Deployment timeout!" && exit 1
+          EOF
+
+      - id: configure_keycloak
+        name: Configure Keycloak
+        run: |
+          CONTAINER="${{ job.services.keycloak.id }}"
+          docker exec -i "${CONTAINER}" /bin/bash <<EOF
+            /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password admin
+            /opt/jboss/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/jboss/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
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 8d758cd..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,50 +0,0 @@
-language: java
-
-cache:
-  directories:
-  - "$HOME/.m2"
-
-jdk:
-- openjdk11
-
-sudo: required
-
-services:
-  - docker
-
-env:
-  - KEYCLOAK_VERSION=7.0.0
-
-before_install:
-  - if [ "$TRAVIS_EVENT_TYPE" != "cron" ]; then docker pull quay.io/keycloak/keycloak:$KEYCLOAK_VERSION; fi
-
-script:
-  - if [ "$TRAVIS_EVENT_TYPE" != "cron" ]; then
-      mvn test package -B &&
-      mkdir target/docker &&
-      cp target/*.jar target/docker/keycloak-protocol-cas.jar &&
-      echo "FROM quay.io/keycloak/keycloak:$KEYCLOAK_VERSION" > target/docker/Dockerfile &&
-      echo "ADD keycloak-protocol-cas.jar /opt/jboss/keycloak/standalone/deployments/" >> target/docker/Dockerfile &&
-      cd target/docker && docker build -t doccrazy/keycloak-cas . && cd ../.. &&
-      docker run -d -p 127.0.0.1:8080:8080 --name keycloak -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin doccrazy/keycloak-cas && sleep 60 &&
-      docker logs keycloak &&
-      docker exec -t keycloak /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password admin &&
-      docker exec -t keycloak /opt/jboss/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 &&
-      docker exec -t keycloak /opt/jboss/keycloak/bin/kcadm.sh get serverinfo -r master --fields "providers(login-protocol(providers(cas)))" | grep cas &&
-      integrationTest/suite.sh
-    ; fi
-  - if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then ./update.sh; fi
-
-before_deploy:
-  - "mvn -DskipTests package"
-  - export RELEASE_JAR=$(ls target/keycloak-protocol-cas-*.jar)
-
-deploy:
-  provider: releases
-  api_key:
-    secure: BPcU12jQ4qs1xAq+Y+6bax+g1AdLatg5E645ISr/NLaKDuWNZxzpMLPf/w9+ngvV5ap5qTz8neoeEbVCLncaIT8wBqlaZnaSnFvVS1huUnwqbh8DzzC6Fmh8DoREpoGo/LV+He1N76bd/lpu0f8VoEqZDtgNYyPAn3xNif+tng8Xa1yh55PqaxB5XlXrArouKCv4jPf+AqzQUMr40Xgn/aQxra6H8PZiEJnxXtweC+UyMNGs5VZkm6nOUW/cpSBppEl6BxyLzJrM2b2pAXQSb85f2EBAIwN38PipwSdckC/3AIhI5Skrx9fEeiuW/YzsZKl7XTohn45fzirc6EzsGBvLucsIda+qMp6Zf4sd8uM0XgiQ1NJyOxWFVFyg3JP00OmJW4BgumfZTL4lzcDUVhn5DubgqZZM3sqvoz75MUSBYewTo3hLBlqxjVA8qe8S738mlNVcpDjwAuAM7/2UP+hcypnjKttQBFt965+yfxjSs3B+KLRQLp7UTmQ+fTcEr72AenQFoXuVpO0k6ghKYomNLLFOzlLk2JCWtsVirjWzJQTZKP5m23jf4qbfyDM3HDenL+N8l3ZOups9gtGpioxkUGKz2IPHrz7XTwh10OpZi32jOPS2BfFOXUQMNVlZAfbIAwXnbo2DWC0AB2Fz//bJbjF9TnOGTUIODos6joo=
-  file: "${RELEASE_JAR}"
-  skip_cleanup: true
-  on:
-    tags: true
-    repo: Doccrazy/keycloak-protocol-cas

--
Gitblit v1.9.1