I'm trying to automate my versioning in android using actions, its my first time using this technology
so I have 3 commands:
./gradlew bumpPatch
./gradlew bumpMinor
./gradlew bumpMajor
How can I determinate which one execute from a PR to master for example :
branch fix/foo --> execute ./gradlew bumpPatch
branch feat/foo --> execute ./gradlew bumpMinor
branch perf/foo --> execute ./gradlew bumpMajor
and how I can do it.
I'm following semantic release so maybe it's better execute the command from the commit message but still don't know how to do both so help it's appreciated.
name: Android CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
Use the following workflow. It only triggers on pull requests against main. It uses conditional steps (if) with an expression that uses the function startsWith.
name: Android CI
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- run: ./gradlew bumpPatch
if: startsWith(github.head_ref, 'fix/')
- run: ./gradlew bumpMinor
if: startsWith(github.head_ref, 'feat/')
- run: ./gradlew bumpMajor
if: startsWith(github.head_ref, 'perf/')
- name: Build with Gradle
run: ./gradlew build
Related
I am trying to make CI process with GitHub Actions for Android project. Before making a real process, the goal is to build gradle and debug apk file automatically.
The job succeed for each step, however, neither build directory nor apk file is being created.
I read various posts and tried each post suggests, but nothing gave me a solution.
What part do I need to change to get the desired result?
Firstly, Below is log I got from ./gradlew build command. It says that the process definitely has gotten into :app:build
> Task :app:lintDebug
> Task :app:lint
> Task :app:check
> Task :app:build
BUILD SUCCESSFUL in 1m 22s
And here is a GitHub Actions Job I made.
Android_CI_Test.yml
name: Android CI Test
on:
pull_request:
branches:
- main
- release
- dev
- staging
push:
branches:
- main
- release
jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set Up java
id: set_up_java
uses: actions/setup-java#v3
with:
java-version: 11
distribution: "corretto"
- name: Set Android SDK
uses: android-actions/setup-android#v2
- name: Cache Gradle
uses: actions/cache#v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/buildSrc/**/*.kt') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grand Gradlew Permission
id: grand_gradlew_permission
run: chmod +x ./gradlew
- name: Validate Gradlew
id: validate_gradlew
uses: gradle/wrapper-validation-action#v1
- name: Set Up Gradle
id: set_up_gradle
uses: gradle/gradle-build-action#v2
- name: Build
id: build_gradle
run: ./gradlew build
- name: Build debug APK
id: build_debug_apk
run: ./gradlew assembleDebug --stacktrace
I tried changing Grand Gradlew Permission to chmod +x ./gradlew , changing Build debug APK to bash ./gradlew assembleDebug or ./gradlew app:assembleDebug but none of them has succeeded.
I am trying to build debug APK using github actions. But Task 'clean' not found in root project 'My Application'. is shown. I am not able to understand what went wrong.
I have placed android.yml like below:
My android.yml looks like this:
name: Android CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x ./MyApplication/gradlew
- name: Build with Gradle
run: ./MyApplication/gradlew build
- name: Build debug APK
run: ./MyApplication/gradlew clean assembleDebug
- name: Upload APK
uses: actions/upload-artifact#v1
with:
name: Debug App
path: ./MyApplication/app/build/outputs/apk/debug/app-debug.apk
EDIT: Checking tasks is a success as shown in the picture.
Settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "My Application"
include ':app'
include ':library'
The problem was the root project should have the 'app' within it. It should not be the case like 'app' within another folder which caused me the issue. Here in my case, all the contents of MyApplication should be under CICDSample. Then it will build the app.
This should be the project structure.
My android.yml file looks like this:
name: Android CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: set up JDK 11
uses: actions/setup-java#v2
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Checking lint
run: ./gradlew lint
- name: Build debug APK
run: ./gradlew clean assembleDebug
- name: Upload APK
uses: actions/upload-artifact#v1
with:
name: Debug App
path: ./app/build/outputs/apk/debug/app-debug.apk
You can download the artifact from here:
Check first:
that your gradlew clean is executed from the root folder of your project,
and that your settings.gradle is not in your .gitignore in that same repository.
The root folder is MyApplication, not My Application.
You can add a ./MyApplication/gradlew tasks to see how gradle is configured.
I created GitHub actions to run to build apk on macOS. but it gives me warning that Artifact pattern :build/app/outputs/apk/release/*.apk did not match any files.
This is a public repo, can someone please help me here. in official docs it says the same path and locally i can build apk successfully (on windows machine).
I used MacOS to generate iOs App which i'll do later.
Link of repo.
magento-mobile-oss
workflow-
name: Magento Mobile
on:
push:
branches: [ oss ]
pull_request:
branches: [ oss ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
channel: stable
env:
KEY_JKS: ${{ secrets.KEY_JKS }}
KEY_PASSWORD: ${{ secrets.ALIAS_PASSWORD }}
ALIAS_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: echo $KEY_JKS > key.jks && flutter pub get && flutter test && flutter build apk --split-per-abi --verbose
- name: Create a Release APK
uses: ncipollo/release-action#v1
with:
artifacts: "build/app/outputs/apk/release/*.apk"
token: ${{ secrets.OSS_TOKEN }}
commit: oss
tag: v1.0.${{ github.run_number }}
Your workflow doesn't build the APK, and therefore, there's no build/app/outputs/apk/release/*.apk file. So the release action doesn't find the location of the artifacts. Here is the workflow you can use to modify yours and tweak it as you wish:
# This is a basic workflow to help you get started with Actions
name: Build Flutter APK
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "develop" branch
push:
branches: ["develop"]
tags:
- "v*"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions:
contents: write
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout#v3
- uses: actions/setup-java#v1
with:
java-version: "12.x"
- name: Setup Flutter
uses: subosito/flutter-action#v1
with:
channel: "beta"
- name: Decode android/neumodore_key.jks
run: echo "${{ secrets.KEYSTORE_JKS_PROD }}" | base64 --decode > android/keystore.jks
- name: Decode android/key.properties
run: echo "${{ secrets.KEY_PROPERTIES_PROD }}" | base64 --decode > android/key.properties
- name: Pub Get Packages
run: flutter pub get
- name: Build APK
run: flutter build apk
- name: Create Release
uses: ncipollo/release-action#v1.10.0
with:
artifacts: "build/app/outputs/apk/release/*.apk"
According to this answer I should run te following command in order to build an apk and sign it?
./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD
And using the android studio I made the following key configuration that is used for building the app:
The generated files in /home/pcmagas/Kwdikas/androidKeys/h330s_fu is contained using the following 2 files:
h300s_fu
private_key.pepk
And the action responsible for building and signing the apk is:
name: pr
on:
push:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout#v1
- name: Set up JDK 8
uses: actions/setup-java#v2
with:
java-version: '8'
distribution: 'adopt'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: test
run: ./gradlew test
- name: build
run: ./gradlew buildRelease
- name: Assemble Release Bundle
run: ./gradlew assembleRelease
Hence the environmental variables:
$KEYFILE
$STORE_PASSWORD
$KEY_ALIAS
$KEY_PASSWORD
Must be configured with github secrets. But what values should I configure for them? I mean what role has the h300s_fu file and the private_key.pepk one?
So im trying to implement a release section on my yml file for a generated artifact, explaining myself: i would like to add an artifact to my releases with my yml file.
Here's the only yml file am working on for an android app:
name: Android CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: mkdir -p app/build/outputs/apk/release
- run: echo hello > app/build/outputs/apk/release/app-release-unsigned.apk
- uses: actions/upload-artifact#v2
with:
name: my-artifact
path: app/build/outputs/apk/release/app-release-unsigned.apk
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Permition Gradlew
run: chmod +x gradlew
- name: Build Gradlew
run: ./gradlew assembleRelease
The actions/upload-artifact#v2 Action is meant for uploading artifacts to GitHub Actions workflow runs, not for adding assets to a GitHub release. If you want to add build assets to a GitHub release, you should instead use the softprops/action-gh-release example described here. I've modified the example to match your specific scenario:
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Upload Release Asset
jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Build project
run: |
mkdir -p app/build/outputs/apk/release
echo hello > app/build/outputs/apk/release/app-release-unsigned.apk
- name: Release with Notes
uses: softprops/action-gh-release#v1
with:
files: app/build/outputs/apk/release/app-release-unsigned.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
You can repeat the final step as needed with different paths for adding further artifacts to the release.