From 18781336af67e367b22a56707d1cbd396506be6b Mon Sep 17 00:00:00 2001 From: nekono <91360587+nkte8@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:49:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?PR=E6=99=82=E3=81=AB=E8=87=AA=E5=8B=95?= =?UTF-8?q?=E7=9A=84=E3=81=AB=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95=E3=83=AD=E3=83=BC=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/auto-pr-format-at-astro.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/auto-pr-format-at-astro.yaml diff --git a/.github/workflows/auto-pr-format-at-astro.yaml b/.github/workflows/auto-pr-format-at-astro.yaml new file mode 100644 index 0000000..fd94f63 --- /dev/null +++ b/.github/workflows/auto-pr-format-at-astro.yaml @@ -0,0 +1,41 @@ +name: Auto-format PR commit code at ./astro + +on: + pull_request: + types: ["opened", "synchronize", "reopened"] + push: + branches: + - main + +permissions: + actions: write + checks: write + contents: write + +jobs: + auto-format: + runs-on: ubuntu-latest + steps: + ## PRのブランチをcheckout + - name: Checkout branch + uses: actions/checkout@v4 + with: + fetch-depth: 2 + ref: ${{ github.head_ref }} + - name: Run Prettier at ./astro + id: format + shell: bash + working-directory: ./astro + run: | + node --version + npm install + npx prettier --write --list-different ./src + + - name: Commit formatted + working-directory: ./astro + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "[Github Action] Auto PR Format" + git push From bda2d0a12cf2a6489cd2d751fc75791d50f90f96 Mon Sep 17 00:00:00 2001 From: nekono <91360587+nkte8@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:01:46 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=82=BF=E3=82=92Deploy=E3=81=B8=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CheckoutするRefを明示 Commit Statusを削除 Cloudflare PagesのAlias URLを正しく出力するように修正 アクションするユーザをgithub-actionsユーザからworkflow実行者に修正 --- .github/workflows/app-manual-deploy.yaml | 38 +++++++++---------- ...mat-at-astro.yaml => format-at-astro.yaml} | 27 ++++++------- 2 files changed, 32 insertions(+), 33 deletions(-) rename .github/workflows/{auto-pr-format-at-astro.yaml => format-at-astro.yaml} (54%) diff --git a/.github/workflows/app-manual-deploy.yaml b/.github/workflows/app-manual-deploy.yaml index 27cf22f..f3386e8 100644 --- a/.github/workflows/app-manual-deploy.yaml +++ b/.github/workflows/app-manual-deploy.yaml @@ -10,11 +10,19 @@ on: jobs: get_env_name: - name: Pre task + name: PreTask uses: ./.github/workflows/get-environment-from-branch.yaml + auto_format: + name: PreTask + uses: ./.github/workflows/format-at-astro.yaml + permissions: + actions: write + checks: write + contents: write + deploy: - needs: ["get_env_name"] + needs: ["get_env_name", "auto_format"] environment: name: ${{ needs.get_env_name.outputs.env_name }} url: ${{ steps.published.outputs.pageurl }} @@ -32,10 +40,14 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 2 + ref: ${{ github.ref_name }} - name: Build shell: bash - run: node --version; npm install && npm run build + run: | + echo "Commit: $(git show --format='%H' --no-patch)" + echo "Node Version: $(node --version)" + npm install && npm run build working-directory: ./astro env: PUBLIC_CREATEPAGES_ENDPOINT: ${{ secrets.PUBLIC_CREATEPAGES_ENDPOINT }} @@ -51,30 +63,16 @@ jobs: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy ./astro/dist --commit-dirty=true --project-name=${{ env.PROJECT_NAME }} - + + ## cloudflare pagesのURLは28文字以上にならない - name: Post publish id: published shell: bash run: | - REF_NAME_ESCAPED=`echo '${{ github.ref_name }}' | sed -E 's/[//_/.]/-/g'`; + REF_NAME_ESCAPED=`echo '${{ github.ref_name }}' | sed -E 's/[//_/.]/-/g' | sed -E 's/(.{,28}).*/\1/' | sed -E 's/-*$//'`; if [[ "${REF_NAME_ESCAPED}" == "${{ github.event.repository.default_branch }}" ]];then REF_NAME_ESCAPED="" else REF_NAME_ESCAPED="${REF_NAME_ESCAPED}." fi echo "pageurl=https://${REF_NAME_ESCAPED}${{ env.PROJECT_NAME }}.pages.dev/" >> $GITHUB_OUTPUT - - - name: Add publish URL as commit status - uses: actions/github-script@v7 - with: - script: | - const sha = context.payload.pull_request?.head.sha ?? context.sha; - await github.rest.repos.createCommitStatus({ - owner: context.repo.owner, - repo: context.repo.repo, - context: 'Cloudflare Pages', - description: 'Deploy to Cloudflare Pages: Click Details to see build result', - state: 'success', - sha, - target_url: "${{ steps.published.outputs.pageurl }}", - }); diff --git a/.github/workflows/auto-pr-format-at-astro.yaml b/.github/workflows/format-at-astro.yaml similarity index 54% rename from .github/workflows/auto-pr-format-at-astro.yaml rename to .github/workflows/format-at-astro.yaml index fd94f63..809e32f 100644 --- a/.github/workflows/auto-pr-format-at-astro.yaml +++ b/.github/workflows/format-at-astro.yaml @@ -1,11 +1,7 @@ -name: Auto-format PR commit code at ./astro +name: Format code at ./astro on: - pull_request: - types: ["opened", "synchronize", "reopened"] - push: - branches: - - main + workflow_call: {} permissions: actions: write @@ -13,7 +9,8 @@ permissions: contents: write jobs: - auto-format: + auto_format: + name: Format code at ./astro runs-on: ubuntu-latest steps: ## PRのブランチをcheckout @@ -21,7 +18,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 2 - ref: ${{ github.head_ref }} + - name: Run Prettier at ./astro id: format shell: bash @@ -34,8 +31,12 @@ jobs: - name: Commit formatted working-directory: ./astro run: | - git config user.name github-actions - git config user.email github-actions@github.com - git add . - git commit -m "[Github Action] Auto PR Format" - git push + git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + if (git diff --shortstat | grep '[0-9]'); then + git add . + git commit -m "[Github Action] Format code at ./astro" + git push + else + echo "no difference found." + fi From 8385694a38c20f1e3d0c513c10c106702b8e35fd Mon Sep 17 00:00:00 2001 From: nkte8 Date: Mon, 15 Apr 2024 12:27:40 +0000 Subject: [PATCH 3/3] [Github Action] Format code at ./astro --- astro/package-lock.json | 4 ++-- astro/src/env/envs.ts | 2 +- astro/src/env/vars.ts | 2 +- astro/src/lib/pagedbAPI/getIds.ts | 4 +++- astro/src/lib/pagedbAPI/getPage.ts | 4 +++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/astro/package-lock.json b/astro/package-lock.json index 997b292..3ccaaa4 100644 --- a/astro/package-lock.json +++ b/astro/package-lock.json @@ -1,12 +1,12 @@ { "name": "skyshare", - "version": "1.4.7", + "version": "1.4.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "skyshare", - "version": "1.4.7", + "version": "1.4.11", "dependencies": { "@astrojs/check": "^0.4.1", "@astrojs/cloudflare": "^8.1.0", diff --git a/astro/src/env/envs.ts b/astro/src/env/envs.ts index cef50d7..5690b2a 100644 --- a/astro/src/env/envs.ts +++ b/astro/src/env/envs.ts @@ -5,4 +5,4 @@ export const qaurl = baseurl + "qa/" export const changeurl = baseurl + "changelog/" export const policyurl = baseurl + "privacypolicy/" export const featureurl = baseurl + "feature/" -export const pagesPrefix = "posts" \ No newline at end of file +export const pagesPrefix = "posts" diff --git a/astro/src/env/vars.ts b/astro/src/env/vars.ts index 81d606e..d44c1a3 100644 --- a/astro/src/env/vars.ts +++ b/astro/src/env/vars.ts @@ -3,7 +3,7 @@ export const githuburl = "https://github.com/nkte8/skyshare" export const zennprofile = "https://zenn.dev/nkte8" export const zennurl = "https://zenn.dev/nkte8/articles/2024-02-03-r01" export const servicename = "Skyshare" -export const servicedesc = `${servicename} is a web application helps bluesky users post to both bluesky or x.com.`; +export const servicedesc = `${servicename} is a web application helps bluesky users post to both bluesky or x.com.` export const authorlink = "https://bsky.app/profile/nekono.dev" export const authorname = "@nekono.dev" export const authormail = "mail@nekono.dev" diff --git a/astro/src/lib/pagedbAPI/getIds.ts b/astro/src/lib/pagedbAPI/getIds.ts index 6e3970e..b8bdbe5 100644 --- a/astro/src/lib/pagedbAPI/getIds.ts +++ b/astro/src/lib/pagedbAPI/getIds.ts @@ -23,7 +23,9 @@ export const api = async ({ }, }) .then(async response => { - const responseParsed = ZodIdsFetchOutput.safeParse(await response.json()) + const responseParsed = ZodIdsFetchOutput.safeParse( + await response.json(), + ) if (!responseParsed.success) { const e: Error = new Error( diff --git a/astro/src/lib/pagedbAPI/getPage.ts b/astro/src/lib/pagedbAPI/getPage.ts index 93ef815..dadee32 100644 --- a/astro/src/lib/pagedbAPI/getPage.ts +++ b/astro/src/lib/pagedbAPI/getPage.ts @@ -27,7 +27,9 @@ export const api = async ({ }, }) .then(async response => { - const responseParsed = ZodPageFetchOutput.safeParse(await response.json()) + const responseParsed = ZodPageFetchOutput.safeParse( + await response.json(), + ) if (!responseParsed.success) { const e: Error = new Error(