Skip to content

Commit

Permalink
Staging CI (#36)
Browse files Browse the repository at this point in the history
* add staging buildtype in gradle

* add staging yml

* updated yml

* added staging in other CI actions

* changed to staging-CI branch

* test remove exact match

* fix

* fixup! added staging in other CI actions

* run staging on tag updates also

* fixup! added staging in other CI actions

* change tag versioning

* convert to staging

* add exact-match

* fix

* update production release

* additional checks

* remove branch dependency

* add match and exclude filter for tags
  • Loading branch information
manorit2001 authored May 8, 2021
1 parent 584ef1a commit fd274ce
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/android-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
RELEASE_API_URL: ${{ secrets.DEBUG_API_URL }}
STAGING_API_URL: ${{ secrets.STAGING_API_URL }}
DEBUG_API_URL: ${{ secrets.DEBUG_API_URL }}
run: |
echo -e "android.enableJetifier=true\nandroid.useAndroidX=true\nandroid.enableBuildCache=true\nkotlin.code.style=official\nkotlin.incremental=true\norg.gradle.configureondemand=true\norg.gradle.daemon=true\norg.gradle.parallel=true\norg.gradle.caching=true" > gradle.properties
Expand All @@ -48,6 +49,7 @@ jobs:
echo "RELEASE_KEY_ALIAS=$RELEASE_KEY_ALIAS" >> gradle.properties
echo "RELEASE_KEY_PASSWORD=$RELEASE_KEY_PASSWORD" >> gradle.properties
echo "RELEASE_API_URL=$RELEASE_API_URL" >> gradle.properties
echo "STAGING_API_URL=$STAGING_API_URL" >> gradle.properties
echo "DEBUG_API_URL=$DEBUG_API_URL" >> gradle.properties
./gradlew assembleDebug
Expand Down
35 changes: 29 additions & 6 deletions .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,49 @@ name: Production Build
on:
push:
tags:
- 'v*'
- 'v[0-9]+.[0-9]+.[0-9]+-prod'

jobs:
check-master:
check-production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check master branch
- name: Check production branch
id: check
run: |
SHA=$(git log -n1 --format=format:"%H")
git checkout master
git checkout production
git merge-base --is-ancestor $SHA HEAD
get-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: production
- name: Get tagname of push
id: check
run: |
git describe --exact-match --match "v*-prod" HEAD
echo "The tag is " $(git describe --exact-match --match "v*-prod" HEAD)
echo ::set-output name=tagname::$(git describe --exact-match --match "v*-prod" HEAD)
outputs:
tagname: ${{ steps.check.outputs.tagname }}

release:
runs-on: ubuntu-latest
needs: check-master
needs:
- check-production
- get-tag
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
ref: production

- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand All @@ -45,6 +66,7 @@ jobs:
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
RELEASE_API_URL: ${{ secrets.RELEASE_API_URL }}
DEBUG_API_URL: ${{ secrets.DEBUG_API_URL }}
STAGING_API_URL: ${{ secrets.STAGING_API_URL }}
RELEASE_SIGN_FILE: ${{ secrets.RELEASE_SIGN_FILE }}
run: |
echo -e "android.enableJetifier=true\nandroid.useAndroidX=true\nandroid.enableBuildCache=true\nkotlin.code.style=official\nkotlin.incremental=true\norg.gradle.configureondemand=true\norg.gradle.daemon=true\norg.gradle.parallel=true\norg.gradle.caching=true" > gradle.properties
Expand All @@ -53,6 +75,7 @@ jobs:
echo "RELEASE_KEY_ALIAS=$RELEASE_KEY_ALIAS" >> gradle.properties
echo "RELEASE_KEY_PASSWORD=$RELEASE_KEY_PASSWORD" >> gradle.properties
echo "RELEASE_API_URL=$RELEASE_API_URL" >> gradle.properties
echo "STAGING_API_URL=$STAGING_API_URL" >> gradle.properties
echo "DEBUG_API_URL=$DEBUG_API_URL" >> gradle.properties
echo "$RELEASE_SIGN_FILE" | base64 -d > sign.jks
Expand All @@ -64,7 +87,7 @@ jobs:

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
run: echo ::set-output name=VERSION::${{ needs.get-tag.outputs.tagname }}

- name: Setup release drafter
id: release-drafter
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Staging Build

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]'
- 'v[0-9]+.[0-9]+.[0-9]+-beta[0-9]'
- 'v[0-9]+.[0-9]+.[0-9]+-alpha[0-9]'

jobs:
check-staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check staging branch
id: check
run: |
SHA=$(git log -n1 --format=format:"%H")
git checkout staging
git merge-base --is-ancestor $SHA HEAD
get-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: staging
- name: Get tagname of push
id: check
run: |
git describe --exact-match --exclude "v*-prod" HEAD
echo "The tag is " $(git describe --exact-match --exclude "v*-prod" HEAD)
echo ::set-output name=tagname::$(git describe --exact-match --exclude "v*-prod" HEAD)
outputs:
tagname: ${{ steps.check.outputs.tagname }}

staging:
runs-on: ubuntu-latest
needs:
- check-staging
- get-tag
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
ref: staging

- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Setup Environment
env:
RELEASE_STORE_FILE: ${{ secrets.RELEASE_STORE_FILE }}
RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }}
RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
RELEASE_API_URL: ${{ secrets.RELEASE_API_URL }}
STAGING_API_URL: ${{ secrets.STAGING_API_URL }}
DEBUG_API_URL: ${{ secrets.DEBUG_API_URL }}
RELEASE_SIGN_FILE: ${{ secrets.RELEASE_SIGN_FILE }}
run: |
echo -e "android.enableJetifier=true\nandroid.useAndroidX=true\nandroid.enableBuildCache=true\nkotlin.code.style=official\nkotlin.incremental=true\norg.gradle.configureondemand=true\norg.gradle.daemon=true\norg.gradle.parallel=true\norg.gradle.caching=true" > gradle.properties
echo "RELEASE_STORE_FILE=../sign.jks" >> gradle.properties
echo "RELEASE_STORE_PASSWORD=$RELEASE_STORE_PASSWORD" >> gradle.properties
echo "RELEASE_KEY_ALIAS=$RELEASE_KEY_ALIAS" >> gradle.properties
echo "RELEASE_KEY_PASSWORD=$RELEASE_KEY_PASSWORD" >> gradle.properties
echo "RELEASE_API_URL=$RELEASE_API_URL" >> gradle.properties
echo "DEBUG_API_URL=$DEBUG_API_URL" >> gradle.properties
echo "STAGING_API_URL=$STAGING_API_URL" >> gradle.properties
echo "$RELEASE_SIGN_FILE" | base64 -d > sign.jks
- name: Staging APK Build
run: ./gradlew assembleStaging

- name: Staging Bundle Build
run: ./gradlew bundleStaging

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${{ needs.get-tag.outputs.tagname }}

- name: Setup Create Release
id: release-drafter
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
body: |
Pre-release: ${{ steps.get_version.outputs.VERSION }}
draft: true
prerelease: true

- name: Upload APK
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release-drafter.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./app/build/outputs/apk/staging/app-staging.apk
asset_name: CGPABook-release-${{ steps.get_version.outputs.VERSION }}.apk
asset_content_type: application/vnd.android.package-archive

- name: Upload AAB
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release-drafter.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./app/build/outputs/bundle/staging/app-staging.aab
asset_name: CGPABook-release-${{ steps.get_version.outputs.VERSION }}.aab
asset_content_type: application/octet-stream
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ android {
signingConfig signingConfigs.releaseSign
buildConfigField "String", "API_URL", "\"$RELEASE_API_URL\""
}
staging {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseSign
buildConfigField "String", "API_URL", "\"$STAGING_API_URL\""
}
debug {
buildConfigField "String", "API_URL", "\"$DEBUG_API_URL\""
}
Expand Down

0 comments on commit fd274ce

Please sign in to comment.