diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml new file mode 100644 index 0000000..30963b4 --- /dev/null +++ b/.github/workflows/firebase-hosting-merge.yml @@ -0,0 +1,20 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on merge +on: + push: + branches: + - main +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_GITHUBACTIONPRACTICE_F87C3 }} + channelId: live + projectId: githubactionpractice-f87c3 diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml new file mode 100644 index 0000000..fcc3ba3 --- /dev/null +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -0,0 +1,21 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on PR +on: pull_request +permissions: + checks: write + contents: read + pull-requests: write +jobs: + build_and_preview: + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_GITHUBACTIONPRACTICE_F87C3 }} + projectId: githubactionpractice-f87c3 diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 2a75c87..1406dce 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -5,8 +5,7 @@ name: Node Continuous Integration on: pull_request: - branches: [ main ] - + branches: [main] jobs: test_pull_request: @@ -16,10 +15,11 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 21 + registry-url: "https://registry.npmjs.org/" - run: npm ci - run: npm test - run: npm run build - - run: npm ci + - run: npm install - run: npm publish env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}} diff --git a/config.js b/config.js new file mode 100644 index 0000000..f1cce85 --- /dev/null +++ b/config.js @@ -0,0 +1,3 @@ +const crypto = require('crypto'); +const crypto_orig_createHash = crypto.createHash; +crypto.createHash = algorithm => crypto_orig_createHash(algorithm === 'md4' ? 'sha256' : algorithm); \ No newline at end of file diff --git a/firebase-debug.log b/firebase-debug.log deleted file mode 100644 index d76f8df..0000000 --- a/firebase-debug.log +++ /dev/null @@ -1,49 +0,0 @@ -[debug] [2025-04-06T10:39:45.633Z] ---------------------------------------------------------------------- -[debug] [2025-04-06T10:39:45.635Z] Command: C:\Program Files\nodejs\node.exe C:\Users\Pooh5821\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js emulators:start -[debug] [2025-04-06T10:39:45.635Z] CLI Version: 14.1.0 -[debug] [2025-04-06T10:39:45.636Z] Platform: win32 -[debug] [2025-04-06T10:39:45.636Z] Node Version: v22.13.0 -[debug] [2025-04-06T10:39:45.636Z] Time: Sun Apr 06 2025 17:39:45 GMT+0700 (Indochina Time) -[debug] [2025-04-06T10:39:45.636Z] ---------------------------------------------------------------------- -[debug] -[debug] [2025-04-06T10:39:45.828Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] -[debug] [2025-04-06T10:39:45.829Z] > authorizing via signed-in user (pooh5821ingkanunt@gmail.com) -[info] i emulators: Starting emulators: hosting {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: hosting"}} -[debug] [2025-04-06T10:39:45.842Z] [logging] Logging Emulator only supports listening on one address (127.0.0.1). Not listening on ::1 -[debug] [2025-04-06T10:39:45.842Z] [hosting] Hosting Emulator only supports listening on one address (127.0.0.1). Not listening on ::1 -[debug] [2025-04-06T10:39:45.842Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400},{"address":"::1","family":"IPv6","port":4400}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"hosting":[{"address":"127.0.0.1","family":"IPv4","port":9999}]},"metadata":{"message":"assigned listening specs for emulators"}} -[debug] [2025-04-06T10:39:45.847Z] [hub] writing locator at C:\Users\Pooh5821\AppData\Local\Temp\hub-githubactionpractice-f87c3.json -[debug] [2025-04-06T10:39:45.862Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:45.862Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:45.863Z] >>> [apiv2][query] GET https://firebasehosting.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/sites -[debug] [2025-04-06T10:39:46.919Z] <<< [apiv2][status] GET https://firebasehosting.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/sites 200 -[debug] [2025-04-06T10:39:46.919Z] <<< [apiv2][body] GET https://firebasehosting.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/sites {"sites":[{"name":"projects/githubactionpractice-f87c3/sites/githubactionpractice-f87c3","defaultUrl":"https://githubactionpractice-f87c3.web.app","type":"DEFAULT_SITE"}]} -[debug] [2025-04-06T10:39:46.919Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:46.919Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:46.919Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/webApps/-/config [none] -[debug] [2025-04-06T10:39:47.857Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/webApps/-/config 200 -[debug] [2025-04-06T10:39:47.858Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3/webApps/-/config {"projectId":"githubactionpractice-f87c3","storageBucket":"githubactionpractice-f87c3.firebasestorage.app","apiKey":"AIzaSyCuQiBdngHv9hdchembY-ZmXvEzCzPaPS8","authDomain":"githubactionpractice-f87c3.firebaseapp.com","messagingSenderId":"315115796797"} -[debug] [2025-04-06T10:39:47.869Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:47.870Z] Checked if tokens are valid: true, expires at: 1743938811343 -[debug] [2025-04-06T10:39:47.870Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3 [none] -[debug] [2025-04-06T10:39:48.281Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3 200 -[debug] [2025-04-06T10:39:48.282Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/githubactionpractice-f87c3 {"projectId":"githubactionpractice-f87c3","projectNumber":"315115796797","displayName":"GitHubActionPractice","name":"projects/githubactionpractice-f87c3","resources":{"hostingSite":"githubactionpractice-f87c3"},"state":"ACTIVE","etag":"1_0a4ac934-b55a-461d-bdb0-e4977f340b2e"} -[info] i hosting[githubactionpractice-f87c3]: Serving hosting files from: public {"metadata":{"emulator":{"name":"hosting"},"message":"Serving hosting files from: \u001b[1mpublic\u001b[22m"}} -[info] + hosting[githubactionpractice-f87c3]: Local server: http://127.0.0.1:9999 {"metadata":{"emulator":{"name":"hosting"},"message":"Local server: \u001b[4m\u001b[1mhttp://127.0.0.1:9999\u001b[22m\u001b[24m"}} -[warn] ! emulators: The Emulator UI is not starting, either because none of the running emulators have a UI component or the Emulator UI cannot determine the Project ID. Pass the --project flag to specify a project. {"metadata":{"emulator":{"name":"hub"},"message":"The Emulator UI is not starting, either because none of the running emulators have a UI component or the Emulator UI cannot determine the Project ID. Pass the --project flag to specify a project."}} -[debug] [2025-04-06T10:39:48.306Z] Could not find VSCode notification endpoint: FetchError: request to http://localhost:40001/vscode/notify failed, reason: . If you are not running the Firebase Data Connect VSCode extension, this is expected and not an issue. -[info] -┌─────────────────────────────────────────────────────────────┐ -│ ✔ All emulators ready! It is now safe to connect your app. │ -└─────────────────────────────────────────────────────────────┘ - -┌──────────┬────────────────┐ -│ Emulator │ Host:Port │ -├──────────┼────────────────┤ -│ Hosting │ 127.0.0.1:9999 │ -└──────────┴────────────────┘ - Emulator Hub host: 127.0.0.1 port: 4400 - Other reserved ports: 4500 - -Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files. - diff --git a/package.json b/package.json index 2726b49..5781494 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { - "name": "devops", + "name": "devops-5821", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "jest", - "build": "webpack src/app.js -o public/bundle.js", + "build": "set NODE_OPTIONS=--openssl-legacy-provider && webpack --config config.js src/app.js -o public/bundle.js", + "start": "set NODE_OPTIONS=--openssl-legacy-provider", "deploy": "firebase deploy --token \"$FIREBASE_TOKEN\" --only hosting" }, "keywords": [], diff --git a/src/app.js b/src/app.js index a8bf206..7ca9261 100644 --- a/src/app.js +++ b/src/app.js @@ -1,13 +1,39 @@ const dayOfTheWeek = (date = new Date()) => { - const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; + const days = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ]; - return days[date.getDay()]; -} + return days[date.getDay()]; +}; +const monthOfTheYear = (date = new Date()) => { + const months = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ]; + return months[date.getMonth()]; +}; try { - document.getElementById('day').innerText = dayOfTheWeek(); -} catch(err) {} + document.getElementById("day").innerText = dayOfTheWeek(); + document.getElementById("month").innerText = monthOfTheYear(); +} catch (err) {} - -exports.dayOfTheWeek = dayOfTheWeek; \ No newline at end of file +exports.dayOfTheWeek = dayOfTheWeek; +exports.monthOfTheYear = monthOfTheYear; diff --git a/src/app.test.js b/src/app.test.js index ac1e73a..8ebe71f 100644 --- a/src/app.test.js +++ b/src/app.test.js @@ -1,7 +1,11 @@ -const { dayOfTheWeek } = require('./app'); +const { dayOfTheWeek } = require("./app"); +const { monthOfTheYear } = require("./app"); - -test('getDay returns the long-format day of the week', () => { - const day = dayOfTheWeek( new Date('3/11/2020') ); - expect( day ).toBe('Wednesday'); -}); \ No newline at end of file +test("getDay returns the long-format day of the week", () => { + const day = dayOfTheWeek(new Date("3/11/2020")); + expect(day).toBe("Wednesday"); +}); +test("getDay returns the month of the year", () => { + const month = monthOfTheYear(new Date("3/11/2020")); + expect(month).toBe("March"); +});