From 5b8a80a42e2bab045a1c3dea62322decf6d13142 Mon Sep 17 00:00:00 2001 From: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Date: Wed, 25 Mar 2026 02:59:18 +0000 Subject: [PATCH] ci: add script --- .gitea/workflows/release.yaml | 70 +++++++++++++++++++++++++++++++++++ .prettierrc | 21 +++++++++++ package.json | 13 ++++++- release.config.ts | 32 ++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/release.yaml create mode 100644 .prettierrc create mode 100644 release.config.ts diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..9d7b207 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,70 @@ +name: Release package + +on: + push: + branches: + - main + - dev-* + - Created_* + +jobs: + release: + permissions: + contents: write + issues: write + pull-requests: write + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + token: ${{ steps.app-token.outputs.token }} + fetch-depth: 0 + + - uses: actions/setup-node@v6 + with: + node-version: latest + + - uses: pnpm/action-setup@v3 + with: + version: latest + run_install: false + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Update dependencies + run: pnpm update + + - name: Format code + run: pnpm format + + - name: Release + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + run: pnpm release + + - name: Commit & Push Changes + if: always() + run: | + if [ -n "$(git status --porcelain)" ]; then + git config --global user.name "gitea-actions" + git config --global user.email "actions-user@noreply.git.demonkernel.io.vn" + + git rm -r --cached . + git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' + git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' + git add . + git commit -m "chore: release [ci skip]" + git push + fi \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b05cabc --- /dev/null +++ b/.prettierrc @@ -0,0 +1,21 @@ +{ + "endOfLine": "lf", + "importOrder": ["^[./]"], + "importOrderSeparation": true, + "importOrderSortSpecifiers": true, + "proseWrap": "always", + "plugins": [ + "@trivago/prettier-plugin-sort-imports", + "prettier-plugin-groovy", + "prettier-plugin-embed", + "prettier-plugin-tailwindcss" + ], + "importOrderParserPlugins": ["typescript", "decorators-legacy", "jsx"], + "embeddedMarkdownComments": ["tw", "tx"], + "printWidth": 80, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false, + "tailwindAttributes": ["/.*(C|c)lassName/"] +} \ No newline at end of file diff --git a/package.json b/package.json index 87ab21e..629953d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "eslint" + "lint": "eslint", + "format": "prettier --write \"./**/*.{js,jsx,ts,tsx,json,md}\"", + "release": "semantic-release" }, "dependencies": { "next": "16.1.7", @@ -15,6 +17,10 @@ "tailwind": "^4.0.0" }, "devDependencies": { + "@semantic-release/exec": "^7.1.0", + "@semantic-release/github": "^12.0.6", + "@semantic-release/npm": "^13.1.5", + "@trivago/prettier-plugin-sort-imports": "^6.0.2", "@tailwindcss/postcss": "^4", "@types/node": "^20", "@types/react": "^19", @@ -22,6 +28,11 @@ "eslint": "^9", "eslint-config-next": "16.1.7", "tailwindcss": "^4", + "prettier": "^3.8.1", + "prettier-plugin-embed": "^0.5.1", + "prettier-plugin-groovy": "^0.2.1", + "prettier-plugin-tailwindcss": "^0.7.2", + "semantic-release": "^25.0.3", "typescript": "^5" } } diff --git a/release.config.ts b/release.config.ts new file mode 100644 index 0000000..37d0a44 --- /dev/null +++ b/release.config.ts @@ -0,0 +1,32 @@ +import type { GlobalConfig } from "semantic-release"; + +const config: GlobalConfig = { + tagFormat: "v${version}", + repositoryUrl: "https://github.com/524H0003/TDTU-auto-login", + branches: ["main", { name: "dev-*", prerelease: "dev" }], + plugins: [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + ["@semantic-release/npm", { npmPublish: false }], + [ + "@semantic-release/exec", + { + prepareCmd: + "pnpm build && node scripts/release.ts ${nextRelease.version}", + }, + ], + [ + "@semantic-release/github", + { + assets: [ + { + path: "release.zip", + name: "TDTU Auto Login v${nextRelease.version}.zip", + }, + ], + }, + ], + ], +}; + +export default config; \ No newline at end of file