forked from folio-org/mod-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (125 loc) · 4.98 KB
/
mvn-dev-build-deploy.yml
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: mvn-dev-build-deploy
on:
push:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
env:
PUBLISH_BRANCH: 'deployment'
OKAPI_URL: 'https://orchid-dev-okapi.folio-dev.indexdata.com'
OKAPI_SECRET_USER: "${{ secrets.ORCHID_DEV_OKAPI_USER }}"
OKAPI_SECRET_PASSWORD: "${{ secrets.ORCHID_DEV_OKAPI_PASSWORD }}"
jobs:
mvn-dev-build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: recursive
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin' # Alternative distribution options are available.
- name: Gather some variables
run: |
echo "MODULE_NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> $GITHUB_ENV
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Set module version
run: |
echo "MODULE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)-${SHA_SHORT}" >> $GITHUB_ENV
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Maven build
run: mvn -B package
- name: SQ analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
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 }} -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
- name: Update ModuleDescriptor Id
run: |
if test -f "$MOD_DESCRIPTOR"; then
echo "Found $MOD_DESCRIPTOR"
cat <<< $(jq '.id = "${{ env.MODULE_NAME}}-${{ env.MODULE_VERSION }}"' $MOD_DESCRIPTOR) > $MOD_DESCRIPTOR
echo "MODULE_DESCRIPTOR=$MOD_DESCRIPTOR" >> $GITHUB_ENV
else
echo "Could not find $MOD_DESCRIPTOR"
exit 1
fi
env:
MOD_DESCRIPTOR: './target/ModuleDescriptor.json'
- name: Read ModuleDescriptor
id: moduleDescriptor
uses: juliangruber/read-file-action@v1
with:
path: ${{ env.MODULE_DESCRIPTOR }}
- name: Login to dev Okapi instance
#if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
id: login-okapi
uses: cyberman54/curl@master
with:
url: "${{ env.OKAPI_URL }}/authn/login"
method: "POST"
accept: 201
timeout: 5000
retries: 3
headers: |
{
"content-type": "application/json",
"x-okapi-tenant": "supertenant"
}
body: |
{
"username": "${{ env.OKAPI_SECRET_USER }}",
"password": "${{ env.OKAPI_SECRET_PASSWORD }}"
}
- name: Login to Index Data Docker Hub account
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and publish Docker image
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: indexdata/${{ env.MODULE_NAME }}:${{ env.MODULE_VERSION }},indexdata/${{ env.MODULE_NAME }}:latest
- name: Get the Okapi login token
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
run: |
echo "OKAPI_TOKEN=${{ fromJSON(steps.login-okapi.outputs.response).headers['x-okapi-token'] }}" >> $GITHUB_ENV
- name: Publish ModuleDescriptor to Okapi
if: ${{ env.CURRENT_BRANCH == env.PUBLISH_BRANCH }}
id: result-okapi
# uses: indiesdev/[email protected]
uses: cyberman54/curl@master
with:
url: "${{ env.OKAPI_URL }}/_/proxy/modules"
method: "POST"
accept: 201
timeout: 10000
headers: |
{
"content-type": "application/json",
"x-okapi-tenant": "supertenant",
"x-okapi-token": "${{ env.OKAPI_TOKEN }}"
}
body: ${{ steps.moduleDescriptor.outputs.content }}
- name: Print module version to job summary
run: |
echo "#### Module Version: ${{ env.MODULE_VERSION }}" >> $GITHUB_STEP_SUMMARY