Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-12558) | Enabled Github Actions #117

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions .github/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/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.dtglibVersion.*$/ext.dtglibVersion = '$NEW_VERSION'/" $VERSION_FILE
}

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 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="### DTG Lib 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.dtg:dtglib"
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' \
-d@post.json

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.dtg:dtglib:$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

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
54 changes: 54 additions & 0 deletions .github/release_notes.sh
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 "### Internal Updates$nl" >> $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.dtg:dtglib:$NEW_VERSION"\'\` >> $RELEASE_NOTES
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build CI

on:
push:
branches: [ "current", "master", "main" ]
pull_request:
branches: [ "current", "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
61 changes: 61 additions & 0 deletions .github/workflows/publish.yml
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
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![](https://jitpack.io/v/com.kaltura/playkit-dtg-android.svg)](https://jitpack.io/#com.kaltura/playkit-dtg-android) [![Travis](https://img.shields.io/travis/kaltura/playkit-dtg-android.svg)](https://travis-ci.org/kaltura/playkit-dtg-android)
[![](https://jitpack.io/v/com.kaltura/playkit-dtg-android.svg)](https://jitpack.io/#com.kaltura/playkit-dtg-android)
[![CI Status](https://github.com/kaltura/playkit-dtg-android/actions/workflows/build.yml/badge.svg)](https://github.com/kaltura/playkit-dtg-android/actions/workflows/build.yml)

# PlayKit DTG - Download To Go

Expand Down
Loading