From bc3c2d3dc902e33dfe289b025eeacd03fcd68662 Mon Sep 17 00:00:00 2001 From: Takashi Shinohara Date: Thu, 31 Oct 2024 18:20:20 +0900 Subject: [PATCH] 0.2.0 release --- .github/workflows/develop.yml | 16 ++++++++ .github/workflows/main.yml | 16 ++++++++ .github/workflows/publish-ghp.yml | 37 +++++++++++++++++ .github/workflows/publish-npm.yml | 27 +++++++++++++ .github/workflows/release.yml | 11 ++++++ .github/workflows/tags.yml | 14 +++++++ .github/workflows/workflow.yml | 66 ------------------------------- README.md | 3 ++ src/index.ts | 11 +++++- test/articles/ebd6b7f4e118f3.md | 41 +++++++++++++++++++ test/package-lock.json | 6 +-- 11 files changed, 178 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/develop.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish-ghp.yml create mode 100644 .github/workflows/publish-npm.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tags.yml delete mode 100644 .github/workflows/workflow.yml create mode 100644 test/articles/ebd6b7f4e118f3.md diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml new file mode 100644 index 0000000..02927ca --- /dev/null +++ b/.github/workflows/develop.yml @@ -0,0 +1,16 @@ +on: + push: + branches: + - develop + +permissions: + id-token: write + packages: write + +jobs: + publish: + name: Publish + uses: ./.github/workflows/publish-ghp.yml + secrets: inherit + with: + environment: dev diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..bdd742b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,16 @@ +on: + push: + branches: + - main + +permissions: + id-token: write + packages: write + +jobs: + publish: + name: Publish + uses: ./.github/workflows/publish-ghp.yml + secrets: inherit + with: + environment: prd diff --git a/.github/workflows/publish-ghp.yml b/.github/workflows/publish-ghp.yml new file mode 100644 index 0000000..28acb1d --- /dev/null +++ b/.github/workflows/publish-ghp.yml @@ -0,0 +1,37 @@ +on: + workflow_call: + inputs: + environment: + required: true + type: string + +jobs: + run: + name: Run + runs-on: ubuntu-latest + steps: + - name: Checkout repos + uses: actions/checkout@v4 + - name: Setup node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + registry-url: https://npm.pkg.github.com/ + always-auth: true + - name: Update package.json + run: npm version ${{vars.BUILD_VERSION}}-${{inputs.environment}}.${{github.run_number}} --no-git-tag-version + - name: Restore source + run: npm ci + - name: Audit source + run: npm audit --omit=dev + - name: Build source + run: npm run build + - name: Create .npmrc + run: | + touch .npmrc + echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}" >> .npmrc + echo "@karamem0:registry=https://npm.pkg.github.com/" >> .npmrc + - name: Publish source + run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml new file mode 100644 index 0000000..bc88287 --- /dev/null +++ b/.github/workflows/publish-npm.yml @@ -0,0 +1,27 @@ +on: workflow_call + +jobs: + run: + name: Run + runs-on: ubuntu-latest + steps: + - name: Checkout repos + uses: actions/checkout@v4 + - name: Setup node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org/ + always-auth: true + - name: Update package.json + run: npm version ${{vars.BUILD_VERSION}} --no-git-tag-version + - name: Restore source + run: npm ci + - name: Audit source + run: npm audit --omit=dev + - name: Build source + run: npm run build + - name: Publish source + run: npm publish --provenance --access=public + env: + NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..10bd7d1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,11 @@ +on: workflow_call + +jobs: + run: + name: Run + runs-on: ubuntu-latest + steps: + - name: Create release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/tags.yml b/.github/workflows/tags.yml new file mode 100644 index 0000000..367754c --- /dev/null +++ b/.github/workflows/tags.yml @@ -0,0 +1,14 @@ +on: + push: + tags: + - v*.*.* + +jobs: + publish: + name: Publish + uses: ./.github/workflows/publish-npm.yml + secrets: inherit + release: + name: Release + uses: ./.github/workflows/release.yml + secrets: inherit diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index 1a104cd..0000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -1,66 +0,0 @@ -on: - push: - branches: - - main - - develop - tags: - - v*.*.* - -permissions: - id-token: write - packages: write - -jobs: - publish-gpr: - runs-on: ubuntu-latest - if: contains(github.ref, 'refs/heads/') - steps: - - name: Checkout repos - uses: actions/checkout@v4 - - name: Setup node.js - uses: actions/setup-node@v4 - with: - node-version: 20.x - registry-url: https://npm.pkg.github.com/ - always-auth: true - - name: Update package.json - run: npm version ${{vars.BUILD_VERSION}}-beta.${{github.run_number}} --no-git-tag-version - - name: Restore source - run: npm ci - - name: Audit source - run: npm audit --omit=dev - - name: Build source - run: npm run build - - name: Create .npmrc - run: | - touch .npmrc - echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}" >> .npmrc - echo "@karamem0:registry=https://npm.pkg.github.com/" >> .npmrc - - name: Publish source - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - publish-npm: - runs-on: ubuntu-latest - if: contains(github.ref, 'refs/tags/') - steps: - - name: Checkout repos - uses: actions/checkout@v4 - - name: Setup node.js - uses: actions/setup-node@v4 - with: - node-version: 20.x - registry-url: https://registry.npmjs.org/ - always-auth: true - - name: Update package.json - run: npm version ${{vars.BUILD_VERSION}} --no-git-tag-version - - name: Restore source - run: npm ci - - name: Audit source - run: npm audit --omit=dev - - name: Build source - run: npm run build - - name: Publish source - run: npm publish --provenance --access=public - env: - NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} diff --git a/README.md b/README.md index 621cc2d..3ddb043 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,11 @@ npx zenn-emoji articles/* -u ``` +既定ではアイキャッチ絵文字が空欄の場合のみ更新します。アイキャッチ絵文字が設定されているファイルも更新したい場合は `-f` オプションを追加してください。 + ## オプション |短い名前|長い名前|説明| |-|-|-| |`-u`|`--update`|対象のファイルを更新します。| +|`-f`|`--force`|アイキャッチ絵文字が設定されているファイルの更新を強制します。| diff --git a/src/index.ts b/src/index.ts index 7ae3cf6..29c4a02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,11 @@ dotenv.config({ path: ['.env', '.env.local'] }); const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +interface Option { + force: boolean, + update: boolean +} + function createOpenAI(): OpenAI { if (process.env.OPENAI_API_KEY) { return new OpenAI({ @@ -64,13 +69,17 @@ function createOpenAI(): OpenAI { program .version(process.env.npm_package_version) .argument('', 'The target files') + .option('-f, --force', 'Force to update the target files') .option('-u, --update', 'Update the target files') - .action(async (files: string[], option: { update: boolean }) => { + .action(async (files: string[], option: Option) => { const prompt = await fs.promises.readFile(path.join(__dirname, 'skills/skprompt.txt'), 'utf-8'); const openai = createOpenAI(); files.forEach(async (file) => { try { const text = await fs.promises.readFile(file, 'utf-8'); + if (!option.force && /emoji: ".+"/u.test(text)) { + return; + } const completion = await openai.chat.completions.create( { messages: [ diff --git a/test/articles/ebd6b7f4e118f3.md b/test/articles/ebd6b7f4e118f3.md new file mode 100644 index 0000000..2710dd3 --- /dev/null +++ b/test/articles/ebd6b7f4e118f3.md @@ -0,0 +1,41 @@ +--- +title: "ハンズオンで学ぶ C# プログラミング" +emoji: "" +type: "tech" +topics: [] +published: false +--- + +# はじめに + +皆さんこんにちは!今日は、C# プログラミングの基本を学ぶハンズオン記事をお届けします。C# は、Microsoft が開発した強力なプログラミング言語であり、特に Windows アプリケーションやゲーム開発でよく使われます。 + +# 準備 + +まず、開発環境を整えましょう。Visual Studio をインストールし、C# プロジェクトを新規作成します。 + +1. Visual Studio を開く +2. 新規プロジェクトを選択 +3. C# コンソールアプリケーションを選ぶ + +# 基本の Hello World + +C# の基本を学ぶために、まずは **Hello World** プログラムを作成します。以下のコードを入力してみてください。 + +```csharp +using System; + +class Program +{ + static void Main() + { + Console.WriteLine("Hello, World!"); + } +} +``` + +このコードを実行すると、コンソールに `Hello, World!` と表示されます。 + +# まとめ + +これが、C# プログラミングの始めの一歩です。この後も、変数や条件分岐、ループ構造などを学んでいきますので、お楽しみに!次回の記事では、もう少し複雑なプログラムに挑戦してみましょう。 diff --git a/test/package-lock.json b/test/package-lock.json index e59a2b0..952a2f3 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -41,9 +41,9 @@ "link": true }, "node_modules/zenn-cli": { - "version": "0.1.157", - "resolved": "https://registry.npmjs.org/zenn-cli/-/zenn-cli-0.1.157.tgz", - "integrity": "sha512-df1JPOwdf3r9dH3YvgiAzfPZllzSB140uXB3EaDtVvxGaDQ2pMsrqaHkhFM6TIAk5KkVX4afN3K4RUwL+S1gKw==", + "version": "0.1.158", + "resolved": "https://registry.npmjs.org/zenn-cli/-/zenn-cli-0.1.158.tgz", + "integrity": "sha512-bvQ96fK+9qw+SKxEmncg/rYU+1u0V6Bh+HuV8By+u4L+VZt/jn9hFyL+KWj/2ncSBDtcEBo6XLsCdNLxlUo+RA==", "license": "MIT", "bin": { "zenn": "dist/server/zenn.js"