Github Actions tutorial for beginners

Eric Lee
2 min readJun 7, 2020

You can build workflow overall CI/CD. There are so many processes that can be set up, but I’m using here only for applying a lint per push in GitHub repository.

First, click the ‘Actions’ in the Github project.

I chose ‘simple workflow’ to apply this one only to build the project with a lint option.

This is to use only to push not for the pull requests in develop branch.

on:  
push:
branches: [ develop ]

Selected ubuntu os for the build.

build:
runs-on: ubuntu-18.04

Set the java version.

java-version: '14.0.1'

Last make a build script.

run: bash ./gradlew build --stacktrace

The full script I used is in the below link.

https://github.com/libliboom/Epub-Viewer-Android/commit/830f4e8f162348c90779f27c7fd0e3b069d4a529

After you push it to your repository, Github Actions will be activated.
Then you can check the workflow you have set.

To apply lint for my Android project, I used ktlint.

I added `ktlint.gradle` file.
To except for Js.kt file, I added `args “!src/**/*Js.kt”` with args into ktlint, ktlintForamt.

repositories {
jcenter()
}

configurations {
ktlint
}

dependencies {
ktlint "com.pinterest:ktlint:0.37.0"
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "src/**/*.kt"
args "!src/**/*Js.kt"
}

check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "src/**/*.kt"
args "!src/**/*Js.kt"
}

You can check the kotlin style with this command.

./gradlew ktlint

You can change the code programatically by this command.

./gradlew ktlintFormat

I added `.editconfig` for the general rule.

[*]
end_of_line = lf
insert_final_newline = true

[*.{kt,kts}]
charset = utf-8
indent_size=4
continuation_indent_size = 4
max_line_length = 120

You can check the concrete changed things in the link.

https://github.com/libliboom/Epub-Viewer-Android/commit/02290ef3360a8bd0a2ac78124104bcd998e619b9

For now, this workflow will be run per every pushed commit into the develop branch.

I have added badge to check the state of Github actions.

You can manipulate the workflow if required.

If you set more manual tasks into Github actions, then better you can concentrate on your creative work.

--

--