Skip to content

Commit c9828a4

Browse files
committed
add ID CI workflows
1 parent 01f37ef commit c9828a4

2 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Very simple workflow to deploy the *latest* published container image with the 'latest' tag.
2+
# This does not post updated module descriptors to okapi, update permissions or enable
3+
# new versions of a module with the tenant. If that is needed, it should be done manually
4+
# via the Okapi API.
5+
6+
name: k8s-deploy-latest
7+
8+
env:
9+
K8S_NAMESPACE: 'folio-dev-new'
10+
K8S_DEPLOYMENT: 'mod-eusage-report-dev'
11+
12+
on:
13+
workflow_dispatch
14+
15+
jobs:
16+
k8s-deploy-latest:
17+
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Deploy latest to K8s
21+
uses: actions-hub/kubectl@v1.34.1
22+
env:
23+
KUBE_CONFIG: ${{ secrets.FOLIO_DEV_NEW_SA_KUBECONFIG }}
24+
with:
25+
args:
26+
-n ${{ env.K8S_NAMESPACE }} rollout restart deployment ${{ env.K8S_DEPLOYMENT }}
27+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: mvn-dev-build-deploy
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
workflow_dispatch:
8+
9+
env:
10+
PUBLISH_BRANCH: 'deployment'
11+
OKAPI_URL: 'https://folio-dev-new-okapi.folio-dev.indexdata.com'
12+
OKAPI_SECRET_USER: "${{ secrets.FOLIO_DEV_NEW_OKAPI_USER }}"
13+
OKAPI_SECRET_PASSWORD: "${{ secrets.FOLIO_DEV_NEW_OKAPI_PASSWORD }}"
14+
OK_SESSION: 'session1'
15+
16+
jobs:
17+
mvn-dev-build-deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
23+
submodules: recursive
24+
25+
- name: Set up JDK 21
26+
uses: actions/setup-java@v5
27+
with:
28+
java-version: 21
29+
distribution: 'temurin' # Alternative distribution options are available.
30+
cache: 'maven'
31+
32+
- name: Prepare okclient
33+
run: git clone https://github.com/indexdata/okclient
34+
35+
- name: Ensure OK and FOLIO login
36+
# So do not proceed with other workflow steps if not available.
37+
run: |
38+
source okclient/ok.sh
39+
OK -S ${{ env.OK_SESSION }} \
40+
-h ${{ env.OKAPI_URL }} \
41+
-t "supertenant" \
42+
-u ${{ env.OKAPI_SECRET_USER }} \
43+
-p ${{ env.OKAPI_SECRET_PASSWORD }}
44+
OK -S ${{ env.OK_SESSION }} -x
45+
46+
- name: Gather some variables
47+
run: |
48+
echo "MODULE_NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> $GITHUB_ENV
49+
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
50+
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
51+
52+
- name: Set module version
53+
run: |
54+
echo "MODULE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)-${SHA_SHORT}" >> $GITHUB_ENV
55+
56+
- name: Cache SonarCloud packages
57+
uses: actions/cache@v4
58+
with:
59+
path: ~/.sonar/cache
60+
key: ${{ runner.os }}-sonar
61+
restore-keys: ${{ runner.os }}-sonar
62+
63+
- name: Cache Maven packages
64+
uses: actions/cache@v4
65+
with:
66+
path: ~/.m2
67+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
68+
restore-keys: ${{ runner.os }}-m2
69+
70+
- name: Maven build
71+
run: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report
72+
73+
- name: SQ analyze
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
76+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
77+
run: mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=indexdata -Dsonar.projectKey=indexdata_${{ github.event.repository.name }}
78+
79+
- name: Update ModuleDescriptor Id
80+
run: |
81+
if test -f "$MOD_DESCRIPTOR"; then
82+
echo "Found $MOD_DESCRIPTOR"
83+
cat <<< $(jq '.id = "${{ env.MODULE_NAME}}-${{ env.MODULE_VERSION }}"' $MOD_DESCRIPTOR) > $MOD_DESCRIPTOR
84+
echo "MODULE_DESCRIPTOR=$MOD_DESCRIPTOR" >> $GITHUB_ENV
85+
else
86+
echo "Could not find $MOD_DESCRIPTOR"
87+
exit 1
88+
fi
89+
env:
90+
MOD_DESCRIPTOR: './target/ModuleDescriptor.json'
91+
92+
- name: Read ModuleDescriptor
93+
id: moduleDescriptor
94+
uses: juliangruber/read-file-action@v1
95+
with:
96+
path: ${{ env.MODULE_DESCRIPTOR }}
97+
98+
- name: Login to Index Data Docker Hub account
99+
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
100+
uses: docker/login-action@v3
101+
with:
102+
username: ${{ secrets.DOCKER_USER }}
103+
password: ${{ secrets.DOCKER_PASSWORD }}
104+
105+
- name: Build and publish Docker image
106+
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
107+
uses: docker/build-push-action@v6
108+
with:
109+
context: .
110+
push: true
111+
tags: indexdata/${{ env.MODULE_NAME }}:${{ env.MODULE_VERSION }},indexdata/${{ env.MODULE_NAME }}:latest
112+
113+
- name: Publish ModuleDescriptor to Okapi
114+
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
115+
run: |
116+
source okclient/ok.sh
117+
echo "Do login ..."
118+
OK -S ${{ env.OK_SESSION }} \
119+
-h ${{ env.OKAPI_URL }} \
120+
-t "supertenant" \
121+
-u ${{ env.OKAPI_SECRET_USER }} \
122+
-p ${{ env.OKAPI_SECRET_PASSWORD }}
123+
echo "Post the MD and report the response status ..."
124+
OK -S ${{ env.OK_SESSION }} _/proxy/modules \
125+
-X post -f ${{ env.MODULE_DESCRIPTOR }}
126+
declare -n NAMEREF_STATUS=${{ env.OK_SESSION }}_HTTPStatus
127+
echo "Response status: $NAMEREF_STATUS"
128+
echo "Do logout ..."
129+
OK -S ${{ env.OK_SESSION }} -x
130+
131+
- name: Print module version to job summary
132+
run: |
133+
echo "#### Module Version: ${{ env.MODULE_VERSION }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)