git action을 통해 github packges 자동 배포 설정은 배우 간단하다.
위와 같이 세 단계를 진행하면 된다.
.yml
name: Gradle Package
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Build with Gradle
run: ./gradlew build -x test
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
run: ./gradlew publish
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
여기서 동적 변수로 할당되는 값들은 전부 git에서 자체적으로 제공해주는 값이기에 우리가 환경변수나 secrets로 추가할 필요는 없다!
이 코드를 그대로 복사하고 붙여넣기 하여 사용해도 전혀 문제 없다!
나는 공통 모듈을 tag를 통한 version를 통한 버전 관리를 진행하기에 tag의 v*(v0.0.1) 가 push 될 때마다 git action이 작동하도록 설정하였다.
이제 공통 모듈을 실제로 다시 업데이트하고 재배포하는 과정을 진행 해보자!
먼저 공통 모듈에서 새로운 기능을 개발 또는 업데이트를 완료했다고 가정하고 다음 순서는 build.gradle의 version을 업데이트 하는 것이다.
나는 새로운 기능이 추가되거나 기존 기능이 제거되지 않는 업데이트는 0.0.1에서 0.0.2로 마지막 숫자만 변경하는 식으로 버전을 변경하였다.
이후 tag를 붙이고 github에 push를 진행하면 된다.
git add .
git commit -m 'refactor: 기능 안정화'
git tag -a v0.0.2 -m 'Release v0.0.2: 버그 수정'
git push origin v0.0.2
위와 같이 진행하고 git repository에서 action을 들어가면 다음과 같이 git action이 작동된 것을 확인 할 수 있다.