Skip to content

Commit 336ba62

Browse files
committed
cleanup build
Signed-off-by: Nick Lawrence <[email protected]>
1 parent 8b9e86b commit 336ba62

File tree

240 files changed

+319
-31300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+319
-31300
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Prepare to release nlp-insights
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, labeled, reopened]
5+
branches:
6+
- main
7+
8+
jobs:
9+
prepare-release:
10+
name: Prepare release
11+
if: ${{ github.event.label.name != 'no-release' }}
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
docker_server: docker.io
16+
docker_org: ntlawrence
17+
docker_repo: nlp-insights
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
- name: Checkout branch
24+
run: |
25+
git fetch
26+
git checkout ${{ github.event.pull_request.head.ref }}
27+
- name: Install python 3.9
28+
run: |
29+
.github/workflows/scripts/install-python-39.sh
30+
npm install -g dockerlint
31+
- name: Docker login
32+
run: echo ${{ secrets.docker_password }} | docker login --username ${{ secrets.docker_username }} --password-stdin ${{ env.docker_server }}
33+
- name: Determine release tag
34+
run: |
35+
set -ex
36+
source .github/workflows/scripts/utils.sh
37+
if [[ "${{ github.event.label.name }}" =~ '^(release-major|release-minor|release-patch)$' ]]; then
38+
RELEASE="${{ github.event.label.name }}"
39+
elif [ -z "${{ github.event.label.name }}" ]; then
40+
&>2 echo "There was no label (valid values are release-major, release-minor, or release-patch), using release-patch"
41+
RELEASE=release-patch
42+
else
43+
&>2 echo "The pull request must have a label in (release-major, release-minor, or release-patch)."
44+
exit 1
45+
fi
46+
47+
echo "VERSION=$(calculate_tag ${{ env.docker_repo }} ${{ env.docker_server }} ${{ env.docker_org }} ${RELEASE} )" >> $GITHUB_ENV
48+
&>2 echo "${VERSION} was assigned as a release tag"
49+
- name: Update release files
50+
run: |
51+
UPDATES=0
52+
.github/workflows/scripts/update_files_with_version.sh \
53+
--project_dir=. \
54+
--version=${{ env.VERSION }} \
55+
--docker_org=${{ env.docker_org }} \
56+
--docker_repo=${{ env.docker_repo}} || UPDATES=$?
57+
58+
&>2 echo "${UPDATES} changes were made to update the release to ${{ env.VERSION }}"
59+
60+
- name: Unit Test
61+
run: ./gradlew test
62+
63+
- name: Static Code Analysis
64+
run: |
65+
if [[ "${{ github.event.pull_request.title }}" =~ '.*\[noFailForSourceProblems\].*' ]]; then
66+
CHECK_SOURCE_NO_FAIL="-PnoFailForSourceProblems"
67+
fi
68+
./gradlew checkSource $CHECK_SOURCE_NO_FAIL
69+
70+
- name: Docker Lint
71+
run: dockerlint
72+
73+
- name: Push Docker Image
74+
run: |
75+
./gradlew checkSource dockerPush -PdockerUser=${{ env.docker_server }}/${{ env.docker_org }}
76+
- name: Commit release updates to git
77+
run: |
78+
git config user.name ${{ github.actor }}
79+
git config user.email "${{ github.actor }}@users.noreply.github.com"
80+
git add -A
81+
git commit --signoff -m "Update to version ${{ env.VERSION }}" || true
82+
git push || true #Ignore errors in case no files have changed

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Add a release tag for nlp-insights
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'services/nlp-insights/gradle.properties'
8+
9+
jobs:
10+
create-release:
11+
name: create release
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- name: Calculate Tag
19+
run: echo "TAG=v$(grep -oP 'version\=\K([0-9]+\.[0-9]+\.[0-9]+)' gradle.properties)" >> $GITHUB_ENV
20+
working-directory: ./services/nlp-insights
21+
- name: Create Release
22+
uses: actions/create-release@v1
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
with:
26+
tag_name: ${{ env.TAG }}
27+
release_name: ${{ env.TAG }}
28+
draft: false
29+
prerelease: true
30+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -ex
3+
sudo apt install python3.9
4+
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
5+
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
6+
sudo update-alternatives --set python3 /usr/bin/python3.9
7+
sudo pip3 install -U pip
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
for i in "$@"; do
4+
case $i in
5+
--project_dir=*)
6+
PROJECT_DIR="${i#*=}"
7+
shift # past argument=value
8+
;;
9+
--version=*)
10+
VERSION="${i#*=}"
11+
shift # past argument=value
12+
;;
13+
--docker_org=*)
14+
DOCKER_ORG="${i#*=}"
15+
shift # past argument=value
16+
;;
17+
--docker_repo=*)
18+
DOCKER_REPO="${i#*=}"
19+
shift # past argument=value
20+
;;
21+
*)
22+
>&2 echo "Unknown option ${i}"
23+
;;
24+
esac
25+
done
26+
27+
if [ -z ${PROJECT_DIR} ] || [ -z ${VERSION} ] || [ -z ${DOCKER_ORG} ] || [ -z ${DOCKER_REPO} ]; then
28+
echo "usage: $0 --project_dir=<dir> --version=<dir> --docker_org=<org> --docker_repo=<repo>"
29+
exit 1
30+
fi
31+
32+
set -ex
33+
updates=0
34+
35+
######
36+
# update values.yaml
37+
######
38+
values_yaml=${PROJECT_DIR}/chart/values.yaml
39+
40+
# Org and Repo
41+
last_org="$(grep "repository:" ${values_yaml} | sed -r 's/\s*repository:\s*(.*)/\1/' | sed -r 's/(.*)\/'${DOCKER_REPO}'/\1/')"
42+
last_org=`echo $last_org | sed -e 's/^[[:space:]]*//'`
43+
44+
if [ "${DOCKER_ORG}" != "${last_org}" ]; then
45+
>&2 echo "Updating ${values_yaml} to org = ${DOCKER_ORG}/${DOCKER_REPO}"
46+
sed -i -e 's/\(\s*repository:\).*/\1 '${DOCKER_ORG}'\/'${DOCKER_REPO}'/' ${values_yaml}
47+
updates=$((updates+1))
48+
fi
49+
50+
# Tag
51+
last_tag="$(grep "tag:" ${values_yaml} | sed -r 's/\s*tag:\s*(.*)/\1/')"
52+
last_tag=`echo $last_tag | sed -e 's/^[[:space:]]*//'`
53+
if [ ${VERSION} != ${last_tag} ]; then
54+
>&2 echo "Updating ${values_yaml} to version ${VERSION}"
55+
sed -i -e 's/\(\s*tag:\).*/\1 '${VERSION}'/' ${values_yaml}
56+
updates=$((updates+1))
57+
fi
58+
59+
60+
######
61+
# Update chart yaml
62+
######
63+
chart_yaml=${PROJECT_DIR}/chart/Chart.yaml
64+
65+
# tag
66+
last_service_helm_ver="$(grep "version:" ${chart_yaml} | sed -r 's/version: (.*)/\1/')"
67+
last_service_helm_ver=`echo $last_service_helm_ver | sed -e 's/^[[:space:]]*//'`
68+
if [[ ${last_service_helm_ver} != ${VERSION} ]]; then
69+
>&2 echo "Updating ${chart_yaml} to version ${VERSION}"
70+
sed -i -e 's/version: '${last_service_helm_ver}'/version: '${VERSION}'/' ${chart_yaml}
71+
updates=$((updates+1))
72+
fi
73+
74+
## Re-package
75+
if [[ ${last_service_helm_ver} != ${VERSION} ]] || [[ ${last_tag} != ${VERSION} ]] || [[ ${last_org} != ${DOCKER_ORG} ]]; then
76+
PACKAGE="${PROJECT_DIR}/docs/charts"
77+
>&2 echo "Repackaging to ${PACKAGE} ..."
78+
#if [ -f ${PACKAGE}/*.tgz ]; then
79+
# rm ${PACKAGE}/*.tgz
80+
#fi
81+
82+
helm package "${PROJECT_DIR}/chart" -d ${PACKAGE}
83+
helm repo index ${PACKAGE}
84+
updates=$((updates+1))
85+
fi
86+
87+
88+
###
89+
# Update gradle.properties
90+
###
91+
last_gradle_tag=$(grep -oP 'version\=\K([0-9]+\.[0-9]+\.[0-9]+)' ${PROJECT_DIR}/gradle.properties)
92+
if [[ ${last_gradle_tag} != ${VERSION} ]]; then
93+
>&2 echo "Updating gradle.properties"
94+
sed -i -e "s/version\W*=.*/version=${VERSION}/" ${PROJECT_DIR}/gradle.properties
95+
updates=$((updates+1))
96+
fi
97+
98+
99+
exit $((updates))

.github/workflows/scripts/utils.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
get_last_tag() {
3+
4+
5+
# These environment vars should be set by the GIT Actions environment
6+
if [ -z "${GITHUB_REPOSITORY}" ]; then
7+
>&2 echo "required environment var (GITHUB_REPOSITORY) was not set"
8+
return 1
9+
fi
10+
11+
if [ -z "${GITHUB_API_URL}" ]; then
12+
>&2 echo "required environment var (GITHUB_API_URL) was not set"
13+
return 1
14+
fi
15+
16+
>&2 echo "retrieving last tag from git ${GITHUB_API_URL} for repo ${GITHUB_REPOSITORY}"
17+
URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases"
18+
last_tag=$(wget -q "${URL}" -O - | jq -r ". | first | .tag_name" | grep -Po "[vV]?\K[0-9]+\.[0-9]+\.[0-9]+")
19+
20+
if [ -z "${last_tag}" ]; then
21+
if [ -f "gradle.properties" ]; then
22+
>&2 echo "No relase found in git, Looking in gradel properties for version"
23+
last_tag=$(grep -oP 'version\=\K([0-9]+\.[0-9]+\.[0-9]+)' gradle.properties)
24+
fi
25+
fi
26+
27+
if [ -z "${last_tag}" ]; then
28+
last_tag="0.0.0"
29+
fi
30+
31+
echo "${last_tag}"
32+
return 0
33+
34+
}
35+
36+
image_exists_with_tag() {
37+
SERVER=$1
38+
ORG=$2
39+
DOCKER_REPO=$3
40+
TAG=$4
41+
42+
docker pull "${SERVER}/${ORG}/${DOCKER_REPO}:${TAG}" >& /dev/null
43+
RC=$?
44+
if [ $RC == 0 ]; then
45+
echo "true"
46+
else
47+
echo "false"
48+
fi
49+
}
50+
51+
increment_tag_level() {
52+
TAG=$1
53+
HOW=$2
54+
55+
56+
MAJOR=$(echo "${TAG}" | cut -d "." -f 1)
57+
MINOR=$(echo "${TAG}" | cut -d "." -f 2)
58+
PATCH=$(echo "${TAG}" | cut -d "." -f 3)
59+
60+
case "${HOW}" in
61+
"release-major")
62+
MAJOR=$((MAJOR+1))
63+
MINOR=0
64+
PATCH=0
65+
;;
66+
"release-minor")
67+
MINOR=$((MINOR+1))
68+
PATCH=0
69+
;;
70+
"release-patch")
71+
PATCH=$((PATCH+1))
72+
;;
73+
*)
74+
PATCH=$((PATCH+1))
75+
;;
76+
esac
77+
echo "${MAJOR}.${MINOR}.${PATCH}"
78+
}
79+
80+
calculate_tag() {
81+
DOCKER_REPO=$1
82+
DOCKER_SERVER=$2
83+
DOCKER_ORG=$3
84+
RELEASE_TYPE=$4
85+
86+
last_tag=$(get_last_tag)
87+
TAG=$(increment_tag_level "${last_tag}" "${RELEASE_TYPE}")
88+
89+
# if there is already a docker image, then we need a new tag
90+
RC=$(image_exists_with_tag "${DOCKER_SERVER}" "${DOCKER_ORG}" "${DOCKER_REPO}" "${TAG}" )
91+
while [ $RC == "true" ]; do
92+
>&2 echo "Tag ${TAG} already has a docker image associated with it, incrementing again..."
93+
TAG=$(increment_tag_level "${TAG}" "release-patch")
94+
RC=$(image_exists_with_tag "${DOCKER_SERVER}" "${DOCKER_ORG}" "${DOCKER_REPO}" "${TAG}")
95+
done
96+
97+
echo "${TAG}"
98+
}
99+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
.gradle
-17 Bytes
Binary file not shown.

.gradle/7.2/dependencies-accessors/gc.properties

Whitespace-only changes.
-264 KB
Binary file not shown.
-17 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)