Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve code]: Formatterの自動適応Workflowの作成 #106

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions .github/workflows/app-manual-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}",
});
42 changes: 42 additions & 0 deletions .github/workflows/format-at-astro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Format code at ./astro

on:
workflow_call: {}

permissions:
actions: write
checks: write
contents: write

jobs:
auto_format:
name: Format code at ./astro
runs-on: ubuntu-latest
steps:
## PRのブランチをcheckout
- name: Checkout branch
uses: actions/checkout@v4
with:
fetch-depth: 2

- 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 --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
4 changes: 2 additions & 2 deletions astro/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion astro/src/env/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
export const pagesPrefix = "posts"
2 changes: 1 addition & 1 deletion astro/src/env/vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion astro/src/lib/pagedbAPI/getIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion astro/src/lib/pagedbAPI/getPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down