— Android, Github Action, CI/CD — 1 min read
Bitriste로 APK 자동 배포하기 에 이어서 Github의 신기능 Github Action으로 안드로이드 APK를 자동빌드하는 것을 만들어 보았다.
Github Action은 사용량에 따라 과금되는데 개인이 사용하는 정도는 무료라고 보면 된다 ,,,
YAML 스크립트로 작성해서 만드는 건데 Bitrise는 workflow가 좀더 유저친화적이고 이해하기 쉬웠다면 코드로만 이루어진 Github Action은 어렵게 느껴질 수 있다. 하지만, Guide에서 하라는 대로 하면 아주 잘된다.. 그리고 사람들이 만들어둔 다양한 tool을 MarketPlace에서 가져다 연동할 수 있다.
https://github.com/features/actions
https://docs.github.com/en/free-pro-team@latest/actions
on: [push, pull_request]
branches (branch 이름)
1on:2 # Trigger the workflow on push or pull request,3 # but only for the main branch4 push:5 branches:6 - main7 pull_request:8 branches:9 - main
master에 push되었을 때 workflow 실행
1name: Deploy2 3on:4 5 push:6 7 branches: master
1- name: Set up JDK 1.82 uses: actions/setup-java@v13 with:4 java-version: 1.85 server-id: github # Value of the distributionManagement/repository/id field of the pom.xml6 settings-path: ${{ github.workspace }} # location for the settings.xml file
1- name: Get current date2 id: date3 run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
1- name: Build APK2 run: bash ./gradlew assembleRelease --stacktrace
https://github.com/marketplace/actions/upload-a-build-artifact 사용
1- name: Upload APK2 uses: actions/upload-artifact@v23 with:4 name: app_${{ steps.date.outputs.date }}5 path: app/release/app-release.apk
https://github.com/marketplace/actions/action-slack 사용
1- name: action-slack2 uses: 8398a7/action-slack@v3.8.03 with:4 status: ${{job.status}}5 author_name: 빌드 알림6 env:7 SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
1SLACK_WEBHOOK_URL 은 Secret에 등록해야함
Github Repository > Settings > Secrets에 등록
1# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created2 3# For more information see: https://github.com/actions/setup-java#publishing-using-gradle4 5 6 7 8name: Deploy9 10on:11 12 push:13 14 branches: master15 16jobs:17 18 build:19 20 runs-on: ubuntu-latest21 22 23 24 25 steps:26 27 - uses: actions/checkout@v228 29 - name: Set up JDK 1.830 31 uses: actions/setup-java@v132 33 with:34 35 java-version: 1.836 37 server-id: github # Value of the distributionManagement/repository/id field of the pom.xml38 39 settings-path: ${{ github.workspace }} # location for the settings.xml file40 41 42 43# - name: Build with Gradle44# run: ./gradlew build45 46 47#Debug용 Key Hash48# - name: get Key Hash49 50# run: keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base6451 52 53 54 - name: Get current date55 id: date56 run: echo "::set-output name=date::$(date +'%Y-%m-%d')"57 58 59 60 - name: Build APK61 run: bash ./gradlew assembleRelease --stacktrace62 63 64 65 - name: Upload APK66 uses: actions/upload-artifact@v267 with:68 name: app_${{ steps.date.outputs.date }}69 path: app/release/app-release.apk70 71 72 73 - name: action-slack74 uses: 8398a7/action-slack@v3.8.075 with:76 status: ${{job.status}}77 author_name: 빌드 알림78 env:79 SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required