Skip to content

Commit

Permalink
add release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
szhang-tyro committed Feb 28, 2024
1 parent bfa7aed commit abfc0bf
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 24 deletions.
35 changes: 35 additions & 0 deletions .ci_steps/bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function bump {
local mode="$1"
local old="$2"
local parts=(${old//./ })
case "$1" in
major)
local bv=$((parts[0] + 1))
NEW_VERSION="${bv}.0.0"
;;
minor)
local bv=$((parts[1] + 1))
NEW_VERSION="${parts[0]}.${bv}.0"
;;
patch)
local bv=$((parts[2] + 1))
NEW_VERSION="${parts[0]}.${parts[1]}.${bv}"
;;
esac
}

BUMP_MODE="patch"

if [ -n "$1" ]; then
BUMP_MODE=$1
fi

OLD_VERSION=$(./gradlew -q printVersionName)
NEW_VERSION="-"

bump $BUMP_MODE $OLD_VERSION
echo "version will be bumped from" $OLD_VERSION "to" $NEW_VERSION

#save outputs
echo "OLD_VERSION=${OLD_VERSION}" >> $GITHUB_OUTPUT
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
18 changes: 18 additions & 0 deletions .ci_steps/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
REPO="https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git"
OLD_VERSION="$1"
NEW_VERSION="$2"
VB_VERSION=$(./gradlew -q printVersionName)
VERSION_FILE=./gradle.properties

sed -i "s/\(version *= *['\"]*\)${VB_VERSION}\(['\"]*\)/\1${NEW_VERSION}\2/" ${VERSION_FILE}

git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add $VERSION_FILE
git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION [skip ci]"
git push $REPO

# check version is bumped
CURRENT_VERSION=$(./gradlew -q printVersionName)
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Package to GitHub Packages
on:
workflow_dispatch:
release:
types: [published]
jobs:
publish-aar:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Linting
run: ./gradlew ciLint
- name: Unit Tests
run: ./gradlew checkTestCoverage
- name: Build Android aar
run: ./gradlew tyro-pay-android:assemble
- name: Publish aar to GitHub Packages
run: ./gradlew publish
env:
GITHUB_PACKAGES_USER: ${{github.actor}}
GITHUB_PACKAGES_TOKEN: ${{secrets.GITHUB_TOKEN}}


70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Release CI
on:
workflow_dispatch:
inputs:
release-type:
description: 'Select release type'
required: true
default: 'draft'
type: choice
options:
- draft
- prerelease
- release

jobs:
git-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
- name : Retrieve Version Name
run: echo "VERSION=$(./gradlew -q printVersionName -Pprefix=v)" >> $GITHUB_OUTPUT
id: android_version
- name: Print Version Name
run: echo "release version ${{steps.android_version.outputs.VERSION}}"
- name: Create GitHub Tag and Release
uses: ncipollo/release-action@v1
with:
${{ inputs.release-type }}: true
generateReleaseNotes: true
tag: "${{steps.android_version.outputs.VERSION}}"
commit: "master"
publish-aar:
needs: git-release
if: ${{inputs.release-type != 'draft'}}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Linting
run: ./gradlew ciLint
- name: Unit Tests
run: ./gradlew checkTestCoverage
- name: Build Android aar
run: ./gradlew tyro-pay-android:assemble
- name: Publish aar to GitHub Packages
run: ./gradlew publish
env:
GITHUB_PACKAGES_USER: ${{github.actor}}
GITHUB_PACKAGES_TOKEN: ${{secrets.GITHUB_TOKEN}}



47 changes: 47 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Bump Version
on:
workflow_dispatch:
inputs:
bump-mode:
description: 'Select bump mode'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major

push:
branches: [master]

jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Retrieve New Version
run: bash ./.ci_steps/bump.sh ${{inputs.bump-mode}}
id: bump
- name: 'Checkout version-bump branch'
run: |
git fetch origin version-bump
git checkout version-bump
- name: Print Current Branch
run: echo "$(git branch --show-current)"
- name: Update Version to version-bump Branch
run: bash ./.ci_steps/update-version.sh ${{steps.bump.outputs.OLD_VERSION}} ${{steps.bump.outputs.NEW_VERSION}}
id: update
- name: Print Bump Results
run: |
echo "New Version: ${{steps.update.outputs.CURRENT_VERSION}}"
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
version=1.0.0
27 changes: 4 additions & 23 deletions tyro-pay-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,14 @@ android {
}
}

version='1.0.0'
task incrementVersion(){
def generateVersion={->
version = buildFile.getText().find(version)
String[] versionParts = version.split('\\.')
int newPatch = versionParts[2].toInteger()+1
versionParts[2] = newPatch.toString()
return versionParts.join('.')
}
task printVersionName {
doLast{
String newVersion = project.findProperty('overrideVersion')?: generateVersion()
String newContent = buildFile.getText().replaceFirst("version='$version'", "version='$newVersion'")
buildFile.setText(newContent)
publishing.publications.release.version=newVersion
String prefix = project.findProperty('prefix')?: ''
println prefix + project.properties.version
}

}

version=project.properties.version

afterEvaluate {
publishing {
Expand All @@ -128,15 +118,6 @@ afterEvaluate {
}
}

task gradlePublishWithVersion(type: GradleBuild) {
if(project.findProperty('newVersion')){
String newVersion = project.findProperty('newVersion')
startParameter.projectProperties = ['overrideVersion':newVersion]

}
tasks = ["incrementVersion", 'publish']
}

task devTest(type: GradleBuild) {
tasks = ['ktLintFormat', 'lint', 'ktlint', 'nexusIQScan', 'checkTestCoverage']
}
Expand Down

0 comments on commit abfc0bf

Please sign in to comment.