-
Notifications
You must be signed in to change notification settings - Fork 37
157 lines (142 loc) · 4.93 KB
/
build-deploy-release.yml
File metadata and controls
157 lines (142 loc) · 4.93 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Build, Deploy, and Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
release_version:
description: 'Release version (e.g., 1.3.3)'
required: true
development_version:
description: 'Next development version (e.g., 1.4.0-SNAPSHOT)'
required: true
jobs:
build:
name: Build and Test JDK 8
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 8
cache: maven
- name: Build and test
run: mvn clean package -B
deploy:
name: Deploy to Maven
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 8
cache: maven
server-id: openmrs-repo-snapshots
server-username: MAVEN_REPO_USERNAME
server-password: MAVEN_REPO_API_KEY
- name: Deploy to Maven
run: mvn deploy -B -DskipTests
env:
MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }}
MAVEN_REPO_API_KEY: ${{ secrets.MAVEN_REPO_API_KEY }}
release:
name: Release to Maven
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout release scripts
uses: actions/checkout@v4
with:
repository: openmrs/openmrs-contrib-bamboo
path: release-scripts
sparse-checkout: release-prepare-perform.sh
sparse-checkout-cone-mode: false
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 8
cache: maven
- name: Configure Maven settings
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<settings>
<servers>
<server>
<id>openmrs-repo-modules</id>
<username>${env.MAVEN_REPO_USERNAME}</username>
<password>${env.MAVEN_REPO_API_KEY}</password>
</server>
<server>
<id>openmrs-repo-snapshots</id>
<username>${env.MAVEN_REPO_USERNAME}</username>
<password>${env.MAVEN_REPO_API_KEY}</password>
</server>
</servers>
</settings>
EOF
- name: Release prepare and perform
run: |
export MAVEN_HOME="$(dirname $(dirname $(readlink -f $(which mvn))))"
# Rewrite SSH SCM URLs to HTTPS so git push uses the checkout token
git config --global url."https://github.com/".insteadOf "git@github.com:"
git config --global --add url."https://github.com/".insteadOf "ssh://git@github.com/"
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
./release-scripts/release-prepare-perform.sh \
-r "$RELEASE_VERSION" \
-d "$DEVELOPMENT_VERSION" \
-e "https://github.com/${{ github.repository }}.git" \
-s
env:
RELEASE_VERSION: ${{ inputs.release_version }}
DEVELOPMENT_VERSION: ${{ inputs.development_version }}
GIT_USER_NAME: openmrs-bot
GIT_USER_EMAIL: info@openmrs.org
MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }}
MAVEN_REPO_API_KEY: ${{ secrets.MAVEN_REPO_API_KEY }}
notify:
name: Notify on failure
needs: [build, deploy, release]
if: always() && contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Send failure email
uses: dawidd6/action-send-mail@v3
with:
server_address: ${{ secrets.SMTP_SERVER }}
server_port: ${{ secrets.SMTP_PORT }}
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: "[${{ github.repository }}] Workflow failed: ${{ github.workflow }} (#${{ github.run_number }})"
to: dev-refapp@openmrs.org
from: openmrs-ci@openmrs.org
body: |
Workflow "${{ github.workflow }}" failed in ${{ github.repository }}.
Branch: ${{ github.ref_name }}
Commit: ${{ github.sha }}
Triggered by: ${{ github.actor }}
View the run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}