Skip to content

Commit b2c830e

Browse files
authored
Bindu, Venki | BAH-1183 | Add github action for bahmni mart github release (#36)
* Bindu, Venki | BAH-1183 | Add github action for bahmni mart github release * Bindu | Add NOTICE file
1 parent 97cd009 commit b2c830e

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
python-version: [2.7]
15+
16+
services:
17+
postgres:
18+
image: postgres
19+
env:
20+
POSTGRES_PASSWORD: password
21+
options: >-
22+
--health-cmd pg_isready
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
ports:
27+
- 5432:5432
28+
29+
mysql:
30+
image: mysql:5.6
31+
env:
32+
MYSQL_ROOT_PASSWORD: password
33+
ports:
34+
- 3306:3306
35+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
36+
37+
steps:
38+
- name: Set up Python ${{ matrix.python-version }}
39+
uses: actions/setup-python@v2
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
- name: Create test_openmrs mysql database
43+
run: |
44+
sudo apt-get update
45+
sudo apt-get install -y mysql-client
46+
mysql --host 127.0.0.1 --port 3306 -uroot -ppassword -e "SHOW DATABASES"
47+
mysql --host 127.0.0.1 --port 3306 -uroot -ppassword -e "create database test_openmrs;"
48+
mysql --host 127.0.0.1 --port 3306 -uroot -ppassword -e "CREATE USER 'test_user'@'127.0.0.1' IDENTIFIED BY 'password';"
49+
mysql --host 127.0.0.1 --port 3306 -uroot -ppassword -e "GRANT ALL PRIVILEGES ON *.* TO 'test_user'@'%' IDENTIFIED by 'password';"
50+
mysql --host 127.0.0.1 --port 3306 -uroot -ppassword -e "FLUSH PRIVILEGES;"
51+
52+
53+
- name: Create test_analytics postgres database
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install --yes --no-install-recommends postgresql-client
57+
- run: |
58+
PGPASSWORD=password psql -h 127.0.0.1 --port 5432 -U postgres -c "CREATE USER test_user WITH PASSWORD 'password' NOCREATEROLE SUPERUSER;"
59+
PGPASSWORD=password psql -h 127.0.0.1 --port 5432 -U postgres -c "CREATE DATABASE test_analytics WITH OWNER test_user;"
60+
PGPASSWORD=password psql -h 127.0.0.1 --port 5432 -U test_user test_analytics -c "CREATE SCHEMA bahmni_mart_scdf;"
61+
62+
- name: chckout code
63+
uses: actions/checkout@v2
64+
- name: Set up JDK 1.8
65+
uses: actions/setup-java@v1
66+
with:
67+
java-version: 1.8
68+
- run: ./scripts/travis/compile.sh
69+
- run: ./scripts/travis/test.sh
70+
- run: ./scripts/travis/createRpm.sh
71+
- shell: bash
72+
env:
73+
TOKEN: ${{ secrets.GH_TOKEN }}
74+
run: |
75+
./scripts/github-release.sh bahmni "$TOKEN"
76+
77+

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Bahmni Bahmni-mart
2-
Copyright 2014 ThoughtWorks, Inc
2+
Copyright (C) 2018 OpenMRS, Inc
33

44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU Affero General Public License as

NOTICE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (C) 2018 OpenMRS, Inc
2+
3+
This product includes software developed under the stewardship of the Bahmni Coalition, under fiscal sponsorship of OpenMRS, Inc. (http://www.openmrs.org/)
4+
5+
This product includes software developed at ThoughtWorks, Inc (http://www.thoughtworks.com/)

scripts/github-release.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
read_version(){
4+
set -e;
5+
local version=$(awk '/^version/{print $NF}' build.gradle | tr -d \');
6+
echo $version
7+
}
8+
9+
create_release() {
10+
local token="$1";
11+
local tag_name="$2";
12+
local commit_sha="$3";
13+
local repo_owner="$4";
14+
15+
curl -s -S -X POST "https://api.github.com/repos/$repo_owner/bahmni-mart/releases" \
16+
-H "Authorization: token $token" \
17+
-H "Content-Type: application/json" \
18+
-d '{"tag_name": "'"$tag_name"'", "name" : "'"$tag_name"'", "target_commitish":"'"$commit_sha"'" }';
19+
}
20+
21+
upload_asset() {
22+
set -e;
23+
24+
local token="$1";
25+
local name="$2";
26+
local file="$3";
27+
local id="$4";
28+
local repo_owner="$5";
29+
30+
curl -s -S -X POST "https://uploads.github.com/repos/$repo_owner/bahmni-mart/releases/$id/assets?name=$name" \
31+
-H "Accept: application/vnd.github.v3+json" \
32+
-H "Authorization: token $token" \
33+
-H "Content-Type: application/x-rpm" \
34+
--data-binary @"$file";
35+
}
36+
37+
main(){
38+
# Assign global variables to local variables
39+
local repo_owner=${args[0]}
40+
local token=${args[1]};
41+
local release_name=$(read_version)
42+
local name="bahmni-mart-${release_name}.noarch.rpm";
43+
local file="$(pwd)/build/distributions/$name";
44+
local commit_sha=$(git rev-parse HEAD)
45+
46+
CREATE_RESPONSE=$(create_release "$token" "$release_name" "$commit_sha" "$repo_owner");
47+
local release_id=$(echo $CREATE_RESPONSE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]');
48+
echo "Created a release with id $release_id"
49+
echo "Created Response ******************************"
50+
echo $CREATE_RESPONSE
51+
52+
# #Upload asset and save the output from curl
53+
UPLOAD_RESPONSE=$(upload_asset "$token" "$name" "$file" "$release_id" "$repo_owner");
54+
echo "Upload Response ******************************"
55+
echo "$UPLOAD_RESPONSE"
56+
}
57+
args=("$@")
58+
main

0 commit comments

Comments
 (0)