Skip to content

Commit

Permalink
Created site reporter (#3)
Browse files Browse the repository at this point in the history
Created a GitHub action that downloads the previous artifacts, download
the current status, and then checks on the servers.

After each run it writes the updated information to the reports,
removing outdated reports (default to 45 days).

Once this is done, the build process runs normally, using the updated
log file.

## Summary

- **New Features**
- Introduced a new GitHub Action for monitoring and reporting health
check statuses of specified URLs.
	- Added a metrics collection and reporting step to the CI/CD workflow.
- Implemented artifact management for storing and retrieving health
check reports.

- **Bug Fixes**
- Updated logging and error handling for health checks, ensuring clearer
status reporting.

- **Documentation**
	- Created a new `.gitignore` file to enhance project cleanliness.

- **Tests**
- Added unit tests to validate functionality for the newly introduced
components.
  • Loading branch information
Bullrich authored Aug 6, 2024
1 parent 030fea0 commit 718ac19
Show file tree
Hide file tree
Showing 21 changed files with 6,172 additions and 151 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,63 @@ on:
push:
branches: ['main']

env:
ARTIFACT_NAME: report

jobs:
get-metrics:
runs-on: ubuntu-latest
name: Cron
defaults:
run:
working-directory: ./log
permissions:
contents: read
actions: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Use cached node_modules
uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- run: npm run build
- run: node dist
id: metrics
env:
SOURCES: |
GitHub->https://github.com
Facebook->https://facebook.com
GITHUB_TOKEN: ${{ github.token }}
JOB_NAME: ${{ github.workflow }}
ARTIFACT_NAME: ${{ env.ARTIFACT_NAME }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ steps.metrics.outputs.file }}
if-no-files-found: error
retention-days: 5
overwrite: true

build-site:
runs-on: ubuntu-latest
name: Build Site
needs: [get-metrics]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -27,6 +80,14 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: logs
- name: Replace reports
run: cat $FILE > ./src/lib/logs.json
env:
FILE: logs/${{ env.ARTIFACT_NAME }}.json
- name: Install dependencies
run: npm ci
- run: npm run build
Expand All @@ -36,6 +97,7 @@ jobs:
path: ./build
if-no-files-found: error
retention-days: 3

deploy-to-github-pages:
environment:
name: github-pages
Expand Down
34 changes: 33 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,41 @@ jobs:
run: npx playwright install
- run: npm run test

action-test:
strategy:
matrix:
command: [lint, build, test]
runs-on: ubuntu-latest
name: Running ${{ matrix.command }}
defaults:
run:
working-directory: ./log
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Use cached node_modules
uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- run: npm run ${{ matrix.command }}

conclude:
runs-on: ubuntu-latest
name: All tests passed
needs: [checks, test]
needs: [checks, test, action-test]
steps:
- run: echo '### Good job! All the tests passed 🚀' >> $GITHUB_STEP_SUMMARY
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ package-lock.json
pnpm-lock.yaml
yarn.lock
src/lib/logs.json

log
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export default [
}
},
{
ignores: ['build/', '.svelte-kit/', 'dist/']
ignores: ['build/', '.svelte-kit/', 'dist/', 'log/']
}
];
18 changes: 18 additions & 0 deletions log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/node_modules
/dist

.DS_Store
*-error.log

# Editor directories and files
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
.idea

# Report files
report.json
report.zip
log/*.json

.env
17 changes: 17 additions & 0 deletions log/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:22 as Builder

WORKDIR /action

COPY package.json yarn.lock ./

RUN npm ci

COPY . .

RUN npm run build

FROM node:22-slim

COPY --from=Builder /action/dist /action

ENTRYPOINT ["node", "/action/index.js"]
12 changes: 12 additions & 0 deletions log/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";


export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
6 changes: 6 additions & 0 deletions log/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: [__dirname + "/src/**/test/**/*.ts"],
};
Loading

0 comments on commit 718ac19

Please # to comment.