Skip to content

Commit

Permalink
fix ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Dec 12, 2023
1 parent b64f9cf commit f6b28c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 44 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ jobs:
node-version-file: .node-version
cache: npm
- run: npm ci
- run: git diff origin/main..HEAD --name-only | xargs npm run validate-blog --
- run: |
git fetch origin main
git diff origin/main..HEAD --name-only | xargs npm run validate-blog --
update-blogmeta:
needs: [validate-blog]
Expand All @@ -69,14 +71,15 @@ jobs:
- uses: actions/checkout@v4
# Checkout pull request HEAD commit instead of merge commit
with:
ref: ${{ github.event.pull_request.head.sha }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-node@v3
with:
node-version-file: .node-version
cache: npm
- run: npm ci
- name: Update blog meta
- name: Update Blog Meta
run: |
git fetch origin main
git diff origin/main..HEAD --name-status | xargs npm run update-blogmeta --
- name: Git Commit
run: |
Expand All @@ -86,8 +89,8 @@ jobs:
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "[Bot] Update blog meta"
git push origin ${{github.head_ref}}
git commit -m "[Bot] Update Blog Meta"
git push
fi
deploy:
Expand Down
67 changes: 28 additions & 39 deletions tools/validate-blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ process.exit(validateBlog() ? 0 : 1)
* 変更されたファイルが許可されているものに含まれているか判定します
*
* 許可されているファイルは以下のとおりです。
* - src/content/blogs/*.md (blogs, tags, authors 以外)
* - src/content/blogs/*.{md, mdx}
* - src/content/blogs/ より一階層下にある画像
* - src/content/authors/*.json
* - src/content/blog-metas/*.json (blogs, tags, authors 以外)
* - src/content/authors/ にある画像
* - src/content/blog-metas/*.json
* - src/content/tags/*.json
* - src/assets/icons/blog/*.svg
* - src/content/tags/ にある画像
*/
function validateBlog() {
let ok = true
Expand All @@ -21,48 +22,20 @@ function validateBlog() {

if (parsedPath.dir === 'src/content/blogs') {
// ブログ本体
if (
parsedPath.ext === '.md' &&
!['blogs', 'tags', 'authors'].includes(parsedPath.name)
)
continue
if (parsedPath.ext === '.md' || parsedPath.ext === '.mdx') continue
} else if (parsedPath.dir === 'src/content/blog-metas') {
// ブログのメタ情報
if (
parsedPath.ext === '.json' &&
!['blogs', 'tags', 'authors'].includes(parsedPath.name)
)
continue
} else if (parsedPath.dir.startsWith('src/content/blogs/')) {
// 画像
if (
[
'.jpg',
'.jpeg',
'.jfif',
'.pjpeg',
'.pjp',
'.png',
'.svg',
'.webp',
'.gif',
'.avif',
'.apng',
].includes(parsedPath.ext)
)
continue
if (parsedPath.ext === '.json') continue
} else if (
// ブログの著者・タグ
['src/content/authors', 'src/content/tags'].includes(parsedPath.dir) &&
parsedPath.ext === '.json'
parsedPath.dir.match(/^src\/content\/blogs\/[^(#/)]*\/[^(#/)]*$/)
) {
continue
// 画像
if (isImage(parsedPath.ext)) continue
} else if (
// ブログのアイコン
parsedPath.dir === 'src/assets/icons/blog' &&
parsedPath.ext === '.svg'
['src/content/authors', 'src/content/tags'].includes(parsedPath.dir)
) {
continue
// ブログの著者・タグ
if (parsedPath.ext === '.json' || isImage(parsedPath.ext)) continue
}

console.log(
Expand All @@ -73,3 +46,19 @@ function validateBlog() {

return ok
}

function isImage(ext: string) {
return [
'.jpg',
'.jpeg',
'.jfif',
'.pjpeg',
'.pjp',
'.png',
'.svg',
'.webp',
'.gif',
'.avif',
'.apng',
].includes(ext)
}

0 comments on commit f6b28c9

Please sign in to comment.