Skip to content

Commit

Permalink
Merge pull request #10 from kts6056/release/242400
Browse files Browse the repository at this point in the history
Release/242400
  • Loading branch information
kts6056 committed Jun 9, 2024
2 parents d416a8e + 58047a1 commit c5927c2
Show file tree
Hide file tree
Showing 63 changed files with 1,168 additions and 78 deletions.
29 changes: 29 additions & 0 deletions .github/actions/calculate-distribution-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Calculate Distribution Version"
description: "Calculate Next Distribution Version"

outputs:
next_year:
description: "다음 정기배포 년도 버전"
value: ${{ steps.calc-next-version.outputs.next_year }}
next_week:
description: "다음 정기배포 주차 버전"
value: ${{ steps.calc-next-version.outputs.next_week }}
next_hotfix:
description: "다음 정기배포 핫픽스 버전"
value: ${{ steps.calc-next-version.outputs.next_hotfix }}

runs:
using: "composite"
steps:
- name: Calc Next Version
id: calc-next-version
shell: bash
run: |
# 다음 정기배포 버전 정보
year=$(TZ="Asia/Seoul" date -d "next week" +'%y')
week=$(TZ="Asia/Seoul" date -d "next week" +'%V')
hotfix=00
echo "next_year=$year" >> $GITHUB_OUTPUT
echo "next_week=$week" >> $GITHUB_OUTPUT
echo "next_hotfix=$hotfix" >> $GITHUB_OUTPUT
45 changes: 45 additions & 0 deletions .github/actions/get-app-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: 'Get App Version'
description: 'Get App Version'

outputs:
year:
description: "앱 버전 중 년도 버전"
value: ${{ steps.get-app-version.outputs.year }}
week:
description: "앱 버전 중 주차 버전"
value: ${{ steps.get-app-version.outputs.week }}
hotfix:
description: "앱 버전 중 핫픽스 버전"
value: ${{ steps.get-app-version.outputs.hotfix }}
version_code:
description: "앱 버전 코드"
value: ${{ steps.get-app-version.outputs.version_code }}
version_name:
description: "앱 버전 이름"
value: ${{ steps.get-app-version.outputs.version_name }}

runs:
using: "composite"
steps:
- name: Get App Version
id: get-app-version
shell: bash
run: |
# app-version.json 파일의 내용을 읽어 변수에 저장해요
year=$(jq .year app-version.json)
week=$(jq .week_no app-version.json)
hotfix=$(jq .hotfix app-version.json)
# VERSION_CODE용 두 자리 변수들
formatted_year=$(printf "%02d" $year)
formatted_week=$(printf "%02d" $week)
formatted_hotfix=$(printf "%02d" $hotfix)
# GITHUB_OUTPUT에 설정해요
{
echo "year=$year"
echo "week=$week"
echo "hotfix=$hotfix"
echo "version_code=$formatted_year$formatted_week$formatted_hotfix"
echo "version_name=$year.$week.$hotfix"
} >> $GITHUB_OUTPUT
14 changes: 14 additions & 0 deletions .github/actions/setup-development-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ./.github/actions/setup-development-environment/action.yml
name: "Setup Development Environment"

runs:
using: "composite"
steps:
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
39 changes: 39 additions & 0 deletions .github/actions/update-app-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Update App Version"

inputs:
year:
description: "업데이트 할 앱 버전 정보 year"
required: true
week_no:
description: "업데이트 할 앱 버전 정보 week_no"
required: true
hotfix:
description: "업데이트 할 앱 버전 정보 hotfix"
required: true
file:
description: "업데이트 할 파일 경로"
required: true

runs:
using: "composite"
steps:
- name: Update app version
shell: bash
run: |
VERSION_FILE="${{ inputs.file }}"
if command -v jq &> /dev/null; then
# jq가 설치되어 있는 경우
jq '.year = $year | .week_no = $week_no | .hotfix = $hotfix' \
--argjson year "${{ inputs.year }}" \
--argjson week_no "${{ inputs.week_no }}" \
--argjson hotfix "${{ inputs.hotfix }}" \
$VERSION_FILE > tmp.$$.json && mv tmp.$$.json $VERSION_FILE
else
# jq가 설치되어 있지 않은 경우
sed -i "s/\"year\": [0-9]\+/\"year\": ${{ inputs.year }}/" $VERSION_FILE
sed -i "s/\"week_no\": [0-9]\+/\"week_no\": ${{ inputs.week_no }}/" $VERSION_FILE
sed -i "s/\"hotfix\": [0-9]\+/\"hotfix\": ${{ inputs.hotfix }}/" $VERSION_FILE
fi
git add $VERSION_FILE
git commit -m "Update app version to ${{ inputs.year }}.${{ inputs.week_no }}.${{ inputs.hotfix }}"
git push origin HEAD
32 changes: 32 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
changelog:
exclude:
authors:
- github-actions
categories:
- title: 'bug'
labels:
- 'bug'
- title: 'documentation'
labels:
- 'documentation'
- title: 'duplicate'
labels:
- 'duplicate'
- title: 'enhancement'
labels:
- 'enhancement'
- title: 'good first issue'
labels:
- 'good first issue'
- title: 'help wanted'
labels:
- 'help wanted'
- title: 'invalid'
labels:
- 'invalid'
- title: 'question'
labels:
- 'question'
- title: 'wontfix'
labels:
- 'wontfix'
32 changes: 32 additions & 0 deletions .github/workflows/create-milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "[CD] Create Weekly Deployment Milestone"

on:
schedule:
- cron: "0 1 * * 1" # 한국 기준으로 매주 월요일 오전 10시에 실행해요
workflow_dispatch:

permissions:
issues: write

jobs:
create-milestone:
runs-on: ubuntu-latest
steps:
- name: Create Milestone
run: |
next_year=$(TZ="Asia/Seoul" date -d "+4 weeks" +'%y')
next_week=$(TZ="Asia/Seoul" date -d "+4 weeks" +'%V')
deployment_date=$(TZ="Asia/Seoul" date -d "4 weeks" +'%Y-%m-%dT09:00:00Z')
version_name="${next_year}.${next_week}.0"
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/milestones \
-d @- << EOF
{
"title": "${version_name}",
"due_on": "${deployment_date}"
}
EOF
46 changes: 46 additions & 0 deletions .github/workflows/create-release-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "[CD] Create Release Branch and Update App Version"

on:
schedule:
- cron: '0 8 * * 5' # 한국 기준으로 매주 금요일 오후 5시에 실행해요
workflow_dispatch:

env:
BRANCH_PREFIX: release

permissions:
contents: write

jobs:
create-release-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Git User Info
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Create Release Branch
id: create-release-branch
run: |
year=$(TZ="Asia/Seoul" date -d "next week" +'%y')
week=$(TZ="Asia/Seoul" date -d "next week" +'%V')
hotfix=00
next_version="${year}${week}${hotfix}"
branch_name="${BRANCH_PREFIX}/$next_version"
git switch -c $branch_name
git push origin $branch_name
echo "브랜치 $branch_name 생성했어요"
- name: Update App Version
uses: ./.github/actions/update-app-version
with:
year: $(TZ="Asia/Seoul" date -d "next week" +'%y')
week_no: $(TZ="Asia/Seoul" date -d "next week" +'%V')
hotfix: 00
file: ./app-version.json
45 changes: 45 additions & 0 deletions .github/workflows/create-release-note.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "[CD] Generate Release Notes"

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: write

jobs:
generate-notes:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Get App Version
id: get-app-version
uses: ./.github/actions/get-app-version

- name: Create Release
run: |
tag_name=${{ steps.get-app-version.outputs.version_code }}
name=${{ steps.get-app-version.outputs.version_name }}
RESPONSE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/kts6056/droidknights-2024-github-actions/releases \
-d "{\"tag_name\":\"$tag_name\",\"target_commitish\":\"main\",\"name\":\"$name\",\"generate_release_notes\":true}" \
-w "\n%{http_code}" -o -)
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)
RESPONSE_CODE=$(echo "$RESPONSE" | tail -n 1)
echo "Response Code: $RESPONSE_CODE"
echo "Response Body: $RESPONSE_BODY"
if [ "$RESPONSE_CODE" -lt 200 ] || [ "$RESPONSE_CODE" -gt 299 ]; then
exit 1
fi
85 changes: 85 additions & 0 deletions .github/workflows/deploy-from-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: "[Build] Deploy APKs on comment"

on:
issue_comment:
types: [created]

permissions:
contents: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
parse-comment:
if: github.event.issue.pull_request != null && startsWith(github.event.comment.body, '/gradle')
runs-on: ubuntu-latest
env:
INPUT: ${{ github.event.comment.body }}
outputs:
gradle-commands: ${{ steps.set-outputs.outputs.result }}
steps:
- name: Set output values
id: set-outputs
run: |
GRADLE_COMMANDS='{"gradle_command":[]}'
if echo "$INPUT" | grep -iq "/gradle all"; then
GRADLE_COMMANDS='{"gradle_command":["assembleDebug","assembleRelease"]}'
elif echo "$INPUT" | grep -iq "/gradle release"; then
GRADLE_COMMANDS='{"gradle_command":["assembleRelease"]}'
elif echo "$INPUT" | grep -iq "/gradle debug"; then
GRADLE_COMMANDS='{"gradle_command":["assembleDebug"]}'
fi
echo "result=$GRADLE_COMMANDS" >> $GITHUB_OUTPUT
build:
needs: parse-comment
runs-on: ubuntu-latest
strategy:
matrix:
gradle-command: ${{ fromJson(needs.parse-comment.outputs.gradle-commands).gradle_command }}
steps:
- name: Add triggered reaction
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket

- name: Checkout
uses: actions/checkout@v4

- name: Setup Development Environment
uses: ./.github/actions/setup-development-environment

- name: Build APK
run: ./gradlew ${{ matrix.gradle-command }}

- name: Set APK path
id: apk
shell: bash
run: |
echo "PATH=$(find . -name *.apk)" >> $GITHUB_OUTPUT
echo "NAME=$(basename $(find . -name *.apk))" >> $GITHUB_OUTPUT
- name: Upload APK to GitHub Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
path: ${{ steps.apk.outputs.PATH }}
name: "${{ github.event.comment.id }}-${{ matrix.gradle-command }}"

- name: Create APK download links
id: create-links
run: |
echo "빌드 파일이 준비 되었어요 [${{ matrix.gradle-command }} Build APK](${{ steps.upload-artifact.outputs.artifact-url }})" > download_links.txt
echo "message=$(cat download_links.txt)"
- name: Post comment with download links
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body-path: 'download_links.txt'
Loading

0 comments on commit c5927c2

Please sign in to comment.