-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from daodaoedu/feat/web-ci-and-cd
feat: web ci and cd
- Loading branch information
Showing
9 changed files
with
2,228 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
name: CI and Deploy workflow | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
branches: "**" | ||
workflow_dispatch: | ||
|
||
env: | ||
DEPLOY_OUTPUT: null | ||
|
||
jobs: | ||
init: | ||
name: Initial Common Steps | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cache dependencies | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
~/.cache/Cypress | ||
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }} | ||
|
||
- name: Install dependencies | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: yarn install --frozen-lockfile | ||
|
||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
needs: init | ||
|
||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cache dependencies | ||
id: cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
~/.cache/Cypress | ||
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }} | ||
|
||
- name: Install dependencies | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: lint | ||
run: | | ||
yarn lint | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git add . | ||
git diff --cached --quiet || echo "changes=true" >> $GITHUB_ENV | ||
- name: Commit lint Changes | ||
if: env.changes == 'true' | ||
run: | | ||
git commit -m "chore: format code" | ||
git push | ||
build_and_deploy: | ||
name: Build and Deploy to Cloudflare | ||
runs-on: ubuntu-latest | ||
environment: production | ||
timeout-minutes: 30 | ||
needs: lint | ||
|
||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build and Deploy to Cloudflare | ||
id: deploy | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | ||
command: pages deploy out | ||
|
||
- name: Save Deploy Output | ||
run: | | ||
echo "DEPLOY_OUTPUT=$(${{ steps.deploy.outputs.command-output }})" >> $GITHUB_ENV | ||
notify_discord: | ||
name: Notify Discord | ||
runs-on: ubuntu-latest | ||
needs: [lint, build_and_deploy] | ||
if: always() | ||
|
||
steps: | ||
- name: Send Discord Notification | ||
run: | | ||
if [ "${{ needs.lint.result }}" == "failure" ]; then | ||
STATUS="❌ Lint Failed" | ||
COLOR=15158332 | ||
elif [ "${{ needs.build_and_deploy.result }}" == "failure" ]; then | ||
STATUS="❌ Build and Deploy Failed" | ||
COLOR=15158332 | ||
else | ||
STATUS="✅ Build Succeeded" | ||
COLOR=3066993 | ||
fi | ||
PAYLOAD=$(cat <<EOF | ||
{ | ||
"embeds": [ | ||
{ | ||
"title": "$STATUS", | ||
"description": "Repository: [${{ github.repository }}](https://github.com/${{ github.repository }})\nBranch: ${{ github.ref_name }}\nWorkflow: ${{ github.workflow }}\n\n${{ env.DEPLOY_OUTPUT }}", | ||
"color": $COLOR | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
curl -H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d "$PAYLOAD" \ | ||
${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: cleanup branch resource | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
workflow_dispatch: | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: write | ||
contents: read | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cleanup cache | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
REPO=${{ github.repository }} | ||
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge | ||
echo "Fetching list of cache key" | ||
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) | ||
echo "Cache keys for PR: $cacheKeysForPR" | ||
## Setting this to not fail the workflow while deleting cache keys. | ||
set +e | ||
echo "Deleting caches..." | ||
for cacheKey in $cacheKeysForPR | ||
do | ||
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm | ||
done | ||
echo "Done" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Delete artifacts | ||
run: | | ||
PR_NUMBER=${{ github.event.pull_request.number }} | ||
artifacts=$(gh api /repos/${{ github.repository }}/actions/artifacts --paginate) | ||
for artifact in $(echo "$artifacts" | jq -r ".artifacts[] | select(.name | startswith(\"PR-$PR_NUMBER-\")) | .id"); do | ||
echo "filtered artifact: $artifact" | ||
gh api -X DELETE /repos/${{ github.repository }}/actions/artifacts/$artifact | ||
done | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Update i18n | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update_i18n: | ||
name: Update i18n Translations | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Fetch i18n Translations | ||
run: node fetchTranslations.js | ||
|
||
- name: Check for i18n changes | ||
id: check_changes | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git add public/locales | ||
git diff --cached --quiet || echo "changes=true" >> $GITHUB_ENV | ||
- name: Commit i18n Changes | ||
if: env.changes == 'true' | ||
run: | | ||
git commit -m "i18n: update translations" | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ yarn-error.log* | |
/public/sw.js.map | ||
/public/workbox-*.js | ||
/public/workbox-*.js.map | ||
|
||
.wrangler | ||
certificates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "daodao-test", | ||
"compatibility_date": "2024-07-29", | ||
"compatibility_flags": ["nodejs_compat"], | ||
"pages_build_output_dir": ".vercel/output/static" | ||
} |
Oops, something went wrong.