-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FEC-12558) | Add github actions support (#158)
- Loading branch information
Showing
10 changed files
with
379 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
#!/bin/bash | ||
# This script takes care of the following tasks, | ||
## 1. Create a new branch from the default 'develop' or 'dev' branch. | ||
## 2. Change the version in version.gradle file. | ||
## 3. Commit and push the version.gradle changes to remote. | ||
## 4. Call `release_notes.sh` to generate release notes. | ||
## 5. Publish and Close it for SONATYPE Maven publishing. | ||
## 6. Create a TAG with release notes and push to remote. | ||
## 7. Notify MS-Teams when the whole process it done. | ||
## IMP: For Patch, there should always be a branch pushed to the remote | ||
## named as `patch/v*.*.*`. Because for patch, script is checking out that branch | ||
## and tagging it. | ||
|
||
exit_on_failure() { | ||
echo "$@" 1>&2 | ||
exit 1 | ||
} | ||
|
||
checkout() { | ||
echo Checking out newtag = "$NEW_TAG", release type = "$RELEASE_TYPE" | ||
|
||
case $RELEASE_TYPE in | ||
Full) | ||
git checkout -b "$BRANCH_NAME" || exit_on_failure "Unable to checkout $BRANCH_NAME";; | ||
Patch) | ||
git checkout "$BRANCH_NAME" || exit_on_failure "Unable to checkout $BRANCH_NAME";; | ||
Update) | ||
git checkout -b "$BRANCH_NAME" "$PREV_TAG" || exit_on_failure "Unable to checkout $BRANCH_NAME";; | ||
esac | ||
} | ||
|
||
set_version() { | ||
echo Setting version of "$REPO_NAME" to "$NEW_VERSION" | ||
|
||
# Changing the version in version.gradle file | ||
perl -pi -e "s/^ext.libVersion.*$/ext.libVersion = '$NEW_VERSION'/" $VERSION_FILE | ||
|
||
# Changing the version in build.gradle file | ||
if [[ "$RELEASE_TYPE" == "Patch" || "$RELEASE_TYPE" == "Update" ]]; then | ||
echo "RELEASE_TYPE = '$RELEASE_TYPE'" | ||
perl -pi -e "s/playkit:playkit:$PLAYKIT_PREV_VERSION/playkit:playkit:$NEW_VERSION/" $BUILD_GRADLE | ||
fi | ||
if [ "$RELEASE_TYPE" == "Full" ]; then | ||
echo "RELEASE_TYPE = '$RELEASE_TYPE'" | ||
perl -pi -e "s/:playkit-android:dev-SNAPSHOT/.playkit:playkit:$NEW_VERSION/" $BUILD_GRADLE | ||
fi | ||
} | ||
|
||
build() { | ||
chmod +x gradlew | ||
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository | ||
} | ||
|
||
release_and_tag() { | ||
git config user.name "$GH_USER_NAME" | ||
git config user.email "<>" | ||
|
||
echo Releasing version $NEW_VERSION of $REPO_NAME to GitHub | ||
set +e | ||
git add $VERSION_FILE | ||
git add $BUILD_GRADLE | ||
git commit -m "Update version to $NEW_TAG" | ||
set -e | ||
git push origin HEAD:$BRANCH_NAME | ||
|
||
# Generate Release notes | ||
bash $RELEASE_NOTES_SCRIPT | ||
|
||
if [[ "$RELEASE_TYPE" = "Patch" || "$RELEASE_TYPE" = "Full" ]]; then | ||
|
||
releaseNotes=$(awk -v d="\\\n" '{s=(NR==1?s:s d)$0}END{print s}' $RELEASE_NOTES) | ||
|
||
|
||
cat << EOF > ./post.json | ||
{ | ||
"name": "$NEW_TAG", | ||
"body": "$releaseNotes", | ||
"tag_name": "$NEW_TAG", | ||
"target_commitish": "$BRANCH_NAME" | ||
} | ||
EOF | ||
fi | ||
|
||
if [ "$RELEASE_TYPE" = "Update" ]; then | ||
JSON_BODY="### IMA Plugin Support\n\n" | ||
JSON_BODY="$JSON_BODY$NEW_TAG\n\n" | ||
JSON_BODY="$JSON_BODY * upgrade to $NEW_TAG\n\n" | ||
JSON_BODY="$JSON_BODY #### Gradle\n\n" | ||
JSON_BODY="$JSON_BODY * implementation 'com.kaltura.playkit:imaplugin" | ||
JSON_BODY="$NEW_VERSION" | ||
JSON_BODY="$JSON_BODY'" | ||
|
||
|
||
cat << EOF > ./post.json | ||
{ | ||
"name": "$NEW_TAG", | ||
"body": "## Changes from [$PREV_TAG](https://github.com/kaltura/$REPO_NAME/releases/tag/$PREV_TAG)\n\n$JSON_BODY", | ||
"tag_name": "$NEW_TAG", | ||
"target_commitish": "$BRANCH_NAME" | ||
} | ||
EOF | ||
fi | ||
|
||
cat post.json | ||
|
||
curl --request POST \ | ||
--url https://api.github.com/repos/kaltura/$REPO_NAME/releases \ | ||
--header "authorization: Bearer $TOKEN" \ | ||
--header 'content-type: application/json' \ | ||
[email protected] | ||
|
||
rm ./post.json | ||
rm $RELEASE_NOTES | ||
|
||
# delete temp branch | ||
#git push origin --delete $BRANCH_NAME | ||
} | ||
|
||
notify_teams() { | ||
COMMIT_SHA=$(git log --pretty=format:'%h' -n 1) | ||
COMMIT_MESSAGE=$(git log --format=%B -n 1 "$COMMIT_SHA") | ||
|
||
color=0072C6 | ||
curl "$TEAMS_WEBHOOK" -d @- << EOF | ||
{ | ||
"@context": "https://schema.org/extensions", | ||
"@type": "MessageCard", | ||
"themeColor": "$color", | ||
"title": "$REPO_NAME | $BRANCH_NAME", | ||
"text": "🎉 Release Ready", | ||
"sections": [ | ||
{ | ||
"facts": [ | ||
{ | ||
"name": "Branch/tag", | ||
"value": "$BRANCH_NAME" | ||
}, | ||
{ | ||
"name": "Commit", | ||
"value": "$COMMIT_SHA ($COMMIT_MESSAGE)" | ||
}, | ||
{ | ||
"name": "Pusher", | ||
"value": "$GH_USER_NAME" | ||
}, | ||
{ | ||
"name": "Gradle line", | ||
"value": "implementation 'com.kaltura.playkit:imaplugin:$COMMIT_SHA'" | ||
} | ||
] | ||
} | ||
], | ||
"potentialAction": [ | ||
{ | ||
"@type": "OpenUri", | ||
"name": "GitHub Release Page", | ||
"targets": [ | ||
{ | ||
"os": "default", | ||
"uri": "$RELEASE_URL" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
} | ||
|
||
RELEASE_TYPE=$RELEASE_TYPE | ||
|
||
export REPO_NAME=$REPO_NAME | ||
MODULE_NAME=$MODULE_NAME | ||
VERSION_FILE=$MODULE_NAME/version.gradle | ||
BUILD_GRADLE=$MODULE_NAME/build.gradle | ||
|
||
REPO_URL=https://github.com/kaltura/$REPO_NAME | ||
export NEW_VERSION=$NEW_VERSION | ||
PREV_VERSION=$PREV_VERSION | ||
TOKEN=$TOKEN | ||
TEAMS_WEBHOOK=$TEAMS_WEBHOOK | ||
|
||
NEW_TAG=v$NEW_VERSION #New Version with 'v' | ||
export PREV_TAG=v$PREV_VERSION #Previous Version with 'v' | ||
RELEASE_URL=$REPO_URL/releases/tag/$NEW_TAG | ||
|
||
if [[ "$RELEASE_TYPE" = "Full" || "$RELEASE_TYPE" = "Update" ]]; then | ||
BRANCH_NAME="release/$NEW_TAG" | ||
fi | ||
|
||
if [ "$RELEASE_TYPE" = "Patch" ]; then | ||
BRANCH_NAME="patch/$NEW_TAG" | ||
fi | ||
|
||
export RELEASE_NOTES="release_notes.md" | ||
RELEASE_NOTES_SCRIPT=".github/release_notes.sh" | ||
GH_USER_NAME="Github Actions Bot KLTR" | ||
|
||
checkout | ||
set_version | ||
build | ||
release_and_tag | ||
notify_teams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
# This script generates "release_notes.md". | ||
# It grabs the logs from the previous defined tag till the HEAD | ||
# and do grep of the PULL requests by filtering using '(#' | ||
# While generating a release notes file, it has 3 sections | ||
# 'New Features', 'Bug Fixes' and 'More Changes' | ||
|
||
# STRICT RULES FOR PULL REQUEST SUBJECT LINE: | ||
## 1. 'New Feature' PR should start with 'feat(FEC-***)'. Add '|' Pipe symbol should be added before subject line starts. | ||
## Example: feat(FEC-1234) | PR Subject line | ||
## 2. 'Bug Fixes' PR should start with 'fix(FEC-***)'. Add '|' Pipe symbol should be added before subject line starts. | ||
## Example: fix(FEC-1234) | PR Subject line | ||
## 3. 'Other Changes' PR which is apart from the above can start like | ||
## Example: FEC-1234 | PR Subject line | ||
|
||
nl=$'\n' | ||
touch $RELEASE_NOTES | ||
echo "## Changes from [$PREV_TAG](https://github.com/kaltura/$REPO_NAME/releases/tag/$PREV_TAG)$nl" > $RELEASE_NOTES | ||
|
||
resultedLine=$(git log $PREV_TAG..HEAD --oneline --grep='(#') | ||
if [[ ! -n "$resultedLine" ]]; then | ||
echo "### Plugin Playkit Support$nl v$NEW_VERSION" >> $RELEASE_NOTES | ||
else | ||
git log $PREV_TAG..HEAD --oneline --grep='(#' | cut -d' ' -f2- | while read -r line; do | ||
echo "$line" | ||
|
||
bugFixes="Bug Fixes" | ||
newFeatures="New Features" | ||
moreChanges="More Changes" | ||
|
||
if [[ "$line" == "fix"* || "$line" == "fix(FEC-"* || "$line" == "fix (FEC-"* ]]; then | ||
|
||
grep -qF -- $bugFixes $RELEASE_NOTES || echo "### "$bugFixes$nl >> $RELEASE_NOTES | ||
modifiedLine=$(echo "$line" | sed 's/fix://' | sed 's/fix//' | sed 's|(\(FEC-[^)]*\))|\1|') | ||
sed -i '/'"$bugFixes"'/a\ | ||
'"- $modifiedLine$nl"'' $RELEASE_NOTES | ||
|
||
elif [[ "$line" == "feat"* || "$line" == "feat(FEC-"* || "$line" == "feat (FEC-"* ]]; then | ||
|
||
grep -qF -- $newFeatures $RELEASE_NOTES || echo "### "$newFeatures$nl >> $RELEASE_NOTES | ||
modifiedLine=$(echo "$line" | sed 's/feat://' | sed 's/feat//' | sed 's|(\(FEC-[^)]*\))|\1|') | ||
sed -i '/'"$newFeatures"'/a\ | ||
'"- $modifiedLine$nl"'' $RELEASE_NOTES | ||
|
||
else | ||
grep -qF -- $moreChanges $RELEASE_NOTES || echo "### "$moreChanges$nl >> $RELEASE_NOTES | ||
echo "- $line$nl" >> $RELEASE_NOTES | ||
|
||
fi | ||
done | ||
fi | ||
|
||
echo "### Gradle" >> $RELEASE_NOTES | ||
echo "$nl* \`implementation 'com.kaltura.playkit:imaplugin:$NEW_VERSION"\'\` >> $RELEASE_NOTES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: build CI | ||
|
||
on: | ||
push: | ||
branches: [ "develop", "master", "main" ] | ||
pull_request: | ||
branches: [ "develop", "master", "main" ] | ||
workflow_call: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
gradle-build: | ||
environment: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo and clone to CI workspace | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
cache: 'gradle' | ||
|
||
- name: Gradle Build... | ||
run: ./gradlew build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: publish CI | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
type: choice | ||
required: true | ||
description: 'Release Type' | ||
options: | ||
- Full | ||
- Patch | ||
new_version: | ||
description: "New Version (Without 'v' Ex: 1.0.0)" | ||
required: true | ||
type: string | ||
prev_version: | ||
description: "Previous Version (Without 'v' Ex: 1.0.0)" | ||
required: true | ||
type: string | ||
|
||
env: | ||
RELEASE_TYPE: ${{ inputs.release_type }} | ||
NEW_VERSION: ${{ inputs.new_version }} | ||
PREV_VERSION: ${{ inputs.prev_version }} | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
NEXUS_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||
NEXUS_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | ||
SIGNING_KEYID: ${{ secrets.SIGNING_KEY_ID }} | ||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | ||
MODULE_NAME: ${{ secrets.MODULE_NAME }} | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yml | ||
|
||
maven-release: | ||
environment: Release | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Checkout repo and clone to CI workspace | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Copy and Decode | ||
run: | | ||
mkdir $PWD/.kltrenv && echo "${{ secrets.SIGNING_KEY }}" > $PWD/.kltrenv/secring.gpg.b64 | ||
base64 -d $PWD/.kltrenv/secring.gpg.b64 > $PWD/.kltrenv/secring.gpg | ||
- name: Run publish Script | ||
run: | | ||
RELEASE_TYPE=${RELEASE_TYPE} NEW_VERSION=${NEW_VERSION} | ||
PREV_VERSION=${PREV_VERSION} REPO_NAME=${REPO_NAME} | ||
TOKEN=${{ secrets.GITHUB_TOKEN }} MODULE_NAME=${MODULE_NAME} TEAMS_WEBHOOK=${{ secrets.TEAMS_WEBHOOK }} bash .github/publish.sh | ||
- name: Delete secring file | ||
run: | | ||
rm -rf $PWD/.kltrenv |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.