Skip to content

Commit 8003e84

Browse files
authored
Merge pull request #25 from NaverPayDev/feature/19_fix
[canary-publish] Add missing `await` and extract correct commit logs.
2 parents fd267b0 + c0c0da7 commit 8003e84

File tree

5 files changed

+184
-6
lines changed

5 files changed

+184
-6
lines changed

canary-publish/README.ko.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,64 @@ jobs:
5050
version_template: '{VERSION}-canary.{DATE}-{COMMITID7}' # (선택) Canary 버전명 템플릿
5151
dry_run: false # (선택) true면 실제 배포 없이 시뮬레이션만 수행
5252
language: 'en' # (선택) 메시지 언어 설정 (en, ko 등)
53-
create_release: false # (선택) true면 Canary 배포 후 GitHub Release 자동 생성. 반드시 @action/checkout에 `fetch-depth: 0` with 옵션을 주세요.
53+
create_release: false # (선택) true면 Canary 배포 후 GitHub Release 자동 생성
5454
```
5555
56+
### ⚠️ `create_release: true` 사용 시 주의사항
57+
58+
이 액션을 `create_release: true` 옵션과 함께 사용할 때는 아래 사항을 반드시 지켜주세요.
59+
60+
1. `actions/checkout`의 `fetch-depth: 0` 설정
61+
62+
전체 git 히스토리를 받아와야 릴리즈 노트가 정확하게 생성됩니다.
63+
64+
```yml
65+
- uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
```
69+
70+
2. `GH_TOKEN` 환경 변수 설정
71+
72+
gh CLI 사용을 위해 인증 토큰이 필요합니다. 아래와 같이 환경 변수로 지정해 주세요.
73+
74+
```yml
75+
env:
76+
GH_TOKEN: ${{ github.token }}
77+
```
78+
79+
(job 또는 workflow 전체에 지정해도 됩니다.)
80+
81+
3. `permissions: contents: write` 권한 추가
82+
83+
릴리즈 생성을 위해 해당 권한이 필요합니다.
84+
85+
```yml
86+
permissions:
87+
contents: write
88+
```
89+
90+
예시 워크플로우
91+
92+
```yml
93+
permissions:
94+
contents: write
95+
96+
jobs:
97+
release:
98+
env:
99+
GH_TOKEN: ${{ github.token }}
100+
steps:
101+
- uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
- uses: NaverPayDev/changeset-actions/canary-publish@main
105+
with:
106+
create_release: true
107+
```
108+
109+
**위 설정이 누락되면 릴리즈 생성이 실패할 수 있습니다. 반드시 확인해 주세요!**
110+
56111
## 실행 결과
57112

58113
![example](./src/assets/example.png)

canary-publish/README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,64 @@ jobs:
5050
version_template: '{VERSION}-canary.{DATE}-{COMMITID7}' # (Optional) Template for the canary version string.
5151
dry_run: false # (Optional) If true, performs a dry run without publishing.
5252
language: 'en' # (Optional) Language for output messages (e.g., en, ko).
53-
create_release: false # (Optional) If true, creates a GitHub Release after canary publishing. Make sure to add `fetch-depth: 0` `with` option to @action/checkout.
53+
create_release: false # (Optional) If true, creates a GitHub Release after canary publishing.
5454
```
5555
56+
### ⚠️ Important Notes for `create_release: true`
57+
58+
When using this action with `create_release: true`, please make sure to:
59+
60+
1. Set `fetch-depth: 0` for `actions/checkout`
61+
62+
This ensures the full git history is available for generating release notes.
63+
64+
```yml
65+
- uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
```
69+
70+
2. Set the `GH_TOKEN` environment variable
71+
72+
The gh CLI requires authentication. Set the token as an environment variable:
73+
74+
```yml
75+
env:
76+
GH_TOKEN: ${{ github.token }}
77+
```
78+
79+
Or at the job/workflow level.
80+
81+
3. Add `permissions: contents: write` to your workflow
82+
83+
This is required for creating releases via the GitHub API.
84+
85+
```yml
86+
permissions:
87+
contents: write
88+
```
89+
90+
Example Workflow Snippet
91+
92+
```yml
93+
permissions:
94+
contents: write
95+
96+
jobs:
97+
release:
98+
env:
99+
GH_TOKEN: ${{ github.token }}
100+
steps:
101+
- uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
- uses: NaverPayDev/changeset-actions/canary-publish@main
105+
with:
106+
create_release: true
107+
```
108+
109+
**If any of these are missing, the release creation step may fail.**
110+
56111
## Execution Results
57112

58113
![example](./src/assets/example.png)

canary-publish/dist/index.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53401,7 +53401,7 @@ function main() {
5340153401
}
5340253402
catch (e) {
5340353403
core.error(e === null || e === void 0 ? void 0 : e.message);
53404-
issueFetchers.addComment(lang_1.LANGUAGES[language].error);
53404+
yield issueFetchers.addComment(lang_1.LANGUAGES[language].error);
5340553405
process.exit(1); // close with error
5340653406
}
5340753407
});
@@ -53658,6 +53658,37 @@ function getPublishedPackageInfos({ packagesDir, execOutput, language, }) {
5365853658
publishedPackages: uniqPackages,
5365953659
};
5366053660
}
53661+
/**
53662+
* changeset 변경 파일 커밋만 제외하고 작업 커밋 로그만 추출
53663+
*/
53664+
function getFilteredCommitMessages({ baseSha, headSha }) {
53665+
// 커밋 해시 목록만 추출
53666+
const shas = (0, node_child_process_1.execSync)(`git log --reverse --pretty=format:"%H" ${baseSha}..${headSha}`, { encoding: 'utf8' })
53667+
.split('\n')
53668+
.filter(Boolean);
53669+
const messages = [
53670+
'## 🚧 Pre-release',
53671+
'',
53672+
`This release is a **pre-release** version.`,
53673+
'Please make sure to thoroughly test it before deploying to production.',
53674+
'',
53675+
'### Changes',
53676+
'',
53677+
];
53678+
for (const sha of shas) {
53679+
// 해당 커밋의 변경 파일 목록 조회
53680+
const files = (0, node_child_process_1.execSync)(`git show --pretty="" --name-only ${sha}`, { encoding: 'utf8' })
53681+
.split('\n')
53682+
.filter(Boolean);
53683+
// .changeset/*.md 외에 변경된 파일이 하나라도 있으면 커밋 메시지에 추가
53684+
const hasNonChangesetFile = files.some((file) => !/\.changeset\/.*\.md$/.test(file));
53685+
if (hasNonChangesetFile) {
53686+
const msg = (0, node_child_process_1.execSync)(`git log -1 --pretty=format:"- %s" ${sha}`, { encoding: 'utf8' });
53687+
messages.push(msg);
53688+
}
53689+
}
53690+
return messages.join('\n');
53691+
}
5366153692
function createReleaseForTags(_a) {
5366253693
return __awaiter(this, arguments, void 0, function* ({ tags, baseSha, headSha, }) {
5366353694
for (const tag of tags) {
@@ -53671,7 +53702,7 @@ function createReleaseForTags(_a) {
5367153702
// IGNORE: release가 없으면 진행
5367253703
}
5367353704
// 커밋 로그 추출하여 릴리즈 노트 생성
53674-
const notes = (0, node_child_process_1.execSync)(`git log ${baseSha}..${headSha} --pretty=format:"- %s"`, { encoding: 'utf8' });
53705+
const notes = getFilteredCommitMessages({ baseSha, headSha });
5367553706
/**
5367653707
* GitHub Release 생성
5367753708
* @see https://cli.github.com/manual/gh_release_create

canary-publish/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async function main() {
164164
core.setOutput('message', message)
165165
} catch (e) {
166166
core.error((e as Error)?.message)
167-
issueFetchers.addComment(LANGUAGES[language].error)
167+
await issueFetchers.addComment(LANGUAGES[language].error)
168168
process.exit(1) // close with error
169169
}
170170
}

canary-publish/src/utils/publish.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,43 @@ export function getPublishedPackageInfos({
4343
}
4444
}
4545

46+
/**
47+
* changeset 변경 파일 커밋만 제외하고 작업 커밋 로그만 추출
48+
*/
49+
function getFilteredCommitMessages({baseSha, headSha}: {baseSha: string; headSha: string}) {
50+
// 커밋 해시 목록만 추출
51+
const shas = execSync(`git log --reverse --pretty=format:"%H" ${baseSha}..${headSha}`, {encoding: 'utf8'})
52+
.split('\n')
53+
.filter(Boolean)
54+
55+
const messages = [
56+
'## 🚧 Pre-release',
57+
'',
58+
`This release is a **pre-release** version.`,
59+
'Please make sure to thoroughly test it before deploying to production.',
60+
'',
61+
'### Changes',
62+
'',
63+
]
64+
65+
for (const sha of shas) {
66+
// 해당 커밋의 변경 파일 목록 조회
67+
const files = execSync(`git show --pretty="" --name-only ${sha}`, {encoding: 'utf8'})
68+
.split('\n')
69+
.filter(Boolean)
70+
71+
// .changeset/*.md 외에 변경된 파일이 하나라도 있으면 커밋 메시지에 추가
72+
const hasNonChangesetFile = files.some((file) => !/\.changeset\/.*\.md$/.test(file))
73+
74+
if (hasNonChangesetFile) {
75+
const msg = execSync(`git log -1 --pretty=format:"- %s" ${sha}`, {encoding: 'utf8'})
76+
messages.push(msg)
77+
}
78+
}
79+
80+
return messages.join('\n')
81+
}
82+
4683
export async function createReleaseForTags({
4784
tags,
4885
baseSha,
@@ -63,7 +100,7 @@ export async function createReleaseForTags({
63100
}
64101

65102
// 커밋 로그 추출하여 릴리즈 노트 생성
66-
const notes = execSync(`git log ${baseSha}..${headSha} --pretty=format:"- %s"`, {encoding: 'utf8'})
103+
const notes = getFilteredCommitMessages({baseSha, headSha})
67104

68105
/**
69106
* GitHub Release 생성

0 commit comments

Comments
 (0)