Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
079b259
Create build_and_release.yml
Gruandal Oct 7, 2025
a1cc22f
Update build_and_release.yml
Gruandal Oct 7, 2025
277af65
Create CI-dev.yml
Gruandal Oct 7, 2025
20e0842
Update and rename CI-dev.yml to deploy.yml
Gruandal Oct 7, 2025
f1045a5
Update deploy.yml
Gruandal Oct 7, 2025
e4ebc46
Update deploy.yml
Gruandal Oct 7, 2025
ce29c58
Update deploy.yml
Gruandal Oct 7, 2025
868480f
Update deploy.yml
Gruandal Oct 7, 2025
e2e6d45
Update deploy.yml
Gruandal Oct 7, 2025
e4416df
Update deploy.yml
Gruandal Oct 7, 2025
c1e6b71
Update deploy.yml
Gruandal Oct 7, 2025
3cdf654
Create unit.sample.test.js
Gruandal Oct 14, 2025
3992b04
Create integration.sample.test.js
Gruandal Oct 14, 2025
95a25f9
Update package.json
Gruandal Oct 14, 2025
8168c27
Update package.json
Gruandal Oct 14, 2025
8487ea2
Update deploy.yml
Gruandal Oct 14, 2025
1fa563e
Update package.json
Gruandal Oct 14, 2025
d481a4d
Update unit.sample.test.js
Gruandal Oct 14, 2025
25177a9
Update deploy.yml
Gruandal Oct 14, 2025
1dd3ad7
Update integration.sample.test.js
Gruandal Oct 14, 2025
9dd452d
Update deploy.yml
Gruandal Oct 14, 2025
de8c92f
Update deploy.yml
Gruandal Oct 14, 2025
235d0ab
Update deploy.yml
Gruandal Oct 14, 2025
795aaeb
Update deploy.yml
Gruandal Oct 14, 2025
77cc436
Update deploy.yml
Gruandal Oct 14, 2025
3a3915e
Update deploy.yml
Gruandal Oct 14, 2025
adee613
Create 1028_test
Gruandal Oct 27, 2025
e71534e
Merge pull request #5 from Gruandal/Gruandal-patch-1
Gruandal Oct 27, 2025
cc87514
Add experimental sections to 1028_test file
Gruandal Oct 27, 2025
8966600
Merge pull request #6 from Gruandal/Gruandal-patch-2
Gruandal Oct 27, 2025
7bec3ca
Update 1028_test
jaybied Oct 27, 2025
aefccfc
Update 1028_test
jayterry Oct 27, 2025
f384171
Update 1028_test
jaybied Oct 27, 2025
e6466fd
Update 1028_test
jayterry Oct 27, 2025
c611bd5
Merge pull request #10 from Gruandal/jayterry-patch-2
Gruandal Oct 27, 2025
bd9a154
Merge branch 'Experiment2_Clean-Merge' into jaybied-patch-2
Gruandal Oct 27, 2025
7c62231
Merge pull request #9 from Gruandal/jaybied-patch-2
Gruandal Oct 27, 2025
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
58 changes: 58 additions & 0 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Release Action

on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v1.0.1)'
required: true
note:
description: 'Release notes'
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- run: zip -r build.zip ./

- uses: actions/upload-artifact@v4
with:
name: build-artifact
path: build.zip

release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
name: build-artifact

- name: Create Release
id: create_release # ← 這行很重要!
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag }}
release_name: Release ${{ github.event.inputs.tag }}
body: ${{ github.event.inputs.note }}
draft: false
prerelease: false

- name: Upload Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # ← 現在就能讀到了
asset_path: ./build.zip
asset_name: build.zip
asset_content_type: application/zip
170 changes: 170 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: CI/CD Deployment Pipeline

on:
workflow_dispatch:
inputs:
force_fail:
description: "Fail tests on purpose (demo the gate)?"
required: false
default: "false"

permissions:
contents: write

jobs:
# === 🏗️ 1. Build job ===
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build project
run: |
echo "🏗️ Building project..."
npm ci
npm run build
zip -r build.zip dist/

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-artifact
path: build.zip

# === ✅ 1.1 Unit tests ===
test-unit:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci || npm i

# ⬇️ 故意讓測試失敗(只在你勾選時)
- name: Fail on purpose (demo)
if: ${{ github.event.inputs.force_fail == 'true' }}
run: |
echo "❌ Forcing unit test failure for demo"; exit 1

- name: Run unit tests
run: npm run test:unit


# === ✅ 1.2 Integration tests (runs on built artifact) ===
test-integration:
needs: test-unit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # ⬅️ 需要這個,npm 才找得到 package.json
- uses: actions/download-artifact@v4
with:
name: build-artifact
path: . # 下載到當前目錄
- name: Normalize artifact path (optional but safe)
run: |
if [ -f build-artifact/build.zip ]; then mv build-artifact/build.zip .; fi
ls -lah
- uses: actions/setup-node@v4
with: { node-version: 20 }
- name: Run integration tests on build.zip
run: npm run test:integration


# === 🚀 2. Deploy to Dev ===
deploy-dev:
needs: test-integration
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-artifact

- name: Release Dev Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: dev-v1.0
NOTE: "Development build release"
run: |
echo "🚀 Deploying development release..."
gh release delete "$TAG" -y || true
git tag -d "$TAG" || true
git push origin :refs/tags/"$TAG" || true
gh release create "$TAG" build.zip --notes "$NOTE"

# === 🧪 3. Deploy to Staging ===
deploy-staging:
needs: deploy-dev
runs-on: ubuntu-latest
environment: staging
env:
TEST_ENV: staging
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-artifact

- name: Release Staging Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: staging-v1.0
NOTE: "Testing pre-production release"
run: |
echo "🧪 Deploying staging release..."
gh release delete "$TAG" -y || true
git tag -d "$TAG" || true
git push origin :refs/tags/"$TAG" || true
gh release create "$TAG" build.zip --notes "$NOTE"

# === 🎉 4. Deploy to Production ===
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production
env:
TEST_ENV: prod
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-artifact

- name: Release Production Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: prod-v1.0
NOTE: "Stable production release"
run: |
echo "🎉 Deploying production release..."
gh release delete "$TAG" -y || true
git tag -d "$TAG" || true
git push origin :refs/tags/"$TAG" || true
gh release create "$TAG" build.zip --notes "$NOTE"
14 changes: 14 additions & 0 deletions 1028_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Experiment 1
Please edit this line!

#Experiment 2

terry - modify
bied testing
terry - modifin
bied test


#Experiment 3
terry - add terry_test file
bied - add bied_test file
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"scripts": {
"format:check": "prettier --check index.js",
"format": "prettier --write index.js",
"build": "ncc build index.js -o dist"
"build": "ncc build index.js -o dist",
"test:unit": "node tests/unit.sample.test.js",
"test:integration": "node tests/integration.sample.test.js"
},
"dependencies": {
"@actions/core": "^1.11.1",
Expand Down
16 changes: 16 additions & 0 deletions tests/integration.sample.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 整合測試:驗證 build 產物存在(你的 build 步驟會產生 build.zip)
const fs = require('fs');

const candidates = ['build.zip', 'build-artifact/build.zip'];
const found = candidates.find(p => fs.existsSync(p));

if (!found) {
console.error('❌ Integration: build.zip not found in expected locations');
process.exit(1);
}
const bytes = fs.statSync(found).size;
if (bytes <= 0) {
console.error(`❌ Integration: ${found} is empty`);
process.exit(1);
}
console.log(`✅ Integration: ${found} present (${bytes} bytes)`);
22 changes: 22 additions & 0 deletions tests/unit.sample.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 單元測試:僅做本地快速檢查,不觸發 action 主程式
const fs = require('fs');

// 1) 必要檔案存在
const mustExist = ['package.json', 'README.md'];
for (const f of mustExist) {
if (!fs.existsSync(f)) {
console.error(`❌ Unit: ${f} missing`);
process.exit(1);
}
}

// 2) package.json 能被解析
try {
JSON.parse(fs.readFileSync('package.json', 'utf8'));
} catch (e) {
console.error('❌ Unit: package.json is invalid JSON');
console.error(e);
process.exit(1);
}

console.log('✅ Unit: repo sanity checks passed');