SonarQube test #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ticketaka-backend-performance | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'zulu' | |
- name: Cache SonarQube packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Cache Gradle packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
- name: Build and analyze with SonarQube | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |
run: | | |
chmod +x ./gradlew | |
./gradlew build sonar --info | |
# Auto-tagging 및 Release 생성 | |
- name: Bump version and push tag | |
id: tag_version | |
uses: mathieudutour/[email protected] # 가져다 쓸 auto tagging 프로그램 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} # secrets.GITHUB_TOKEN 는 자동생성됨 | |
- name: Create a GitHub release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.tag_version.outputs.new_tag }} | |
release_name: Release ${{ steps.tag_version.outputs.new_tag }} | |
body: ${{ steps.tag_version.outputs.changelog }} | |
# Docker 이미지 빌드 및 Harbor에 Push | |
- name: Docker meta | |
id: docker_meta | |
uses: crazy-max/ghaction-docker-meta@v1 | |
with: | |
images: harbor.hotsun.store/ticketaka/ticketaka-performance | |
tag-semver: | | |
{{version}} | |
{{major}}.{{minor}} | |
- name: Login to Harbor | |
run: | | |
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login harbor.hotsun.store -u "${{ secrets.HARBOR_USERNAME }}" --password-stdin | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and push to Harbor | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: true | |
tags: harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }} | |
# Kubernetes 배포를 위한 Kustomize 업데이트 | |
- name: Checkout for Kustomize repository | |
uses: actions/checkout@v2 | |
with: | |
# kubernetes yaml 파일 저장 | |
repository: F1T4-HOTSUN/manifest # k8s yaml 파일이 있는 repo | |
ref: main # branch 이름 | |
# 내 repository에 push 하기 위한 Personal Access Token이 필요 | |
token: ${{ secrets.PAT }} # Github Action token을 발급받아서 repo secrect에 등록해줘야한다 | |
path: manifest # 최상위 경로로 repository와 동일하게 설정 | |
# 새 이미지 버전으로 파일의 태그값 수정 | |
# cd path 수정 | |
# kustomize로 image tag 값 변경 | |
- name: Update Kubernetes resources | |
run: | | |
pwd | |
cd manifest/resources/performance | |
kustomize edit set image harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }} | |
cat kustomization.yaml | |
# 수정된 kustomization.yaml 파일(manifest) commit push | |
- name: Commit manifest files | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
run: | | |
cd manifest | |
git config --global user.email ${{ secrets.USER_EMAIL_MJ }} | |
git config --global user.name ${{ secrets.USER_NAME_MJ }} | |
git config --global github.token ${{ secrets.PAT }} | |
git commit -am "Update image tag harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }}" | |
git push -u origin main | |