Skip to content

Commit cee9acc

Browse files
authored
Merge pull request #3 from Lissy93/fix/workflow-automations
Fix/workflow automations
2 parents 5a420a2 + 1da304a commit cee9acc

File tree

6 files changed

+110
-36
lines changed

6 files changed

+110
-36
lines changed

.github/README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,27 @@ You can then start the server with `node build`.
2929
<details>
3030
<summary>More Deployment Options</summary>
3131

32-
#### Option 4 - Source: Static
32+
#### Option 4 - GitHub Pages
33+
Fork the repo.<br>
34+
Head to the Actions tab, find the "Deploy to GitHub Pages" workflow, and trigger it.<br>
35+
Then go to Settings > Pages > Source and select the `gh-pages` branch.<br>
36+
Visit `https://<your-username>.github.io/networking-toolbox/` to see your deployed app.
37+
38+
#### Option 5 - Source: Static
3339
Follow the dev steps below.
3440
Then run `npm run build:static` to compile output.<br>
3541
And upload the contents of `./build` to any web server, CDN or static host.
3642

37-
#### Option 5 - Source: Docker
43+
#### Option 6 - Source: Docker
3844
Follow the dev steps below.
3945
Then run `docker build -t networking-toolbox .` to build the image.<br>
4046
You can then start the container with `docker run -p 8080:80 networking-toolbox`.
4147

42-
#### Option 6 - GitHub Pages
43-
Fork the repo.<br>
44-
Head to the Actions tab, find the "Deploy to GitHub Pages" workflow, and trigger it.<br>
45-
Then go to Settings > Pages > Source and select the `gh-pages` branch.<br>
46-
Visit `https://<your-username>.github.io/networking-toolbox/` to see your deployed app.
48+
#### Option 7 - Source: Other Platforms
49+
You can build the app from source for a variety of platforms. This is done via SvelteKit adapters.<br>
50+
First, follow the dev steps below.
51+
Then, simply set the `DEPLOY_ENV` environmental variable, to one of `vercel`, `node`, `docker`, `netlify`, `static` or just `auto`, and build the app<br>
52+
For example: `DEPLOY_ENV='node' npm run build`
4753
</details>
4854

4955
---
@@ -71,6 +77,30 @@ Before merging, code must pass all unit and end-to-end tests, as well as linting
7177
yarn test
7278
```
7379

80+
<details>
81+
<summary><h4>Project Commands</h4></summary>
82+
83+
##### Building
84+
- `npm run dev` - Starts the development server with hot reload/HMR
85+
- `npm run build` - Builds the app for production
86+
- Note: choose adapter for platform by setting the `DEPLOY_ENV` var (see above)
87+
- `npm run preview` - Test your build locally (build required first)
88+
- `npm start` - Starts the production app (build required first)
89+
90+
##### Testing
91+
- `npm test` — Run unit tests with Vitest
92+
- `npm run test:api` — Run API tests
93+
- `npm run test:e2e` — Run Playwright end-to-end tests
94+
- `npm run test:coverage` — Generate test coverage
95+
96+
##### Checking
97+
- `npm run check` — SvelteKit checks (types & diagnostics)
98+
- `npm run types` — TypeScript-specific strict checking
99+
- `npm run lint` — ESLint on all TS and Svelte files
100+
- `npm run format` — Format files with Prettier
101+
- `npm run build-check` — Quitley check build works
102+
</details>
103+
74104
---
75105

76106
### Contributing

.github/workflows/docker.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ on:
2121
type: boolean
2222

2323
env:
24-
REPO_NAME: 'lissy93/networking-toolbox'
25-
# REPO_NAME: ${{ vars.REPO_NAME || github.repository }}
24+
REPO_NAME: ${{ github.repository }}
2625

2726
jobs:
2827
build:
@@ -77,23 +76,38 @@ jobs:
7776
uses: docker/login-action@v3
7877
with:
7978
registry: ghcr.io
80-
username: ${{ github.actor }}
79+
username: ${{ github.repository_owner }}
8180
password: ${{ secrets.GITHUB_TOKEN }}
8281

82+
- name: 📋 Extract metadata
83+
id: meta
84+
uses: docker/metadata-action@v5
85+
with:
86+
images: ghcr.io/${{ env.REPO_NAME }}
87+
tags: |
88+
type=raw,value=${{ steps.tags.outputs.tags }}
89+
labels: |
90+
org.opencontainers.image.title=Networking Toolbox
91+
org.opencontainers.image.description=All-in-one Swiss Army knife for sysadmins and network engineers - a collection of 100+ offline-first essential networking tools in a single, easy-to-use Docker image.
92+
org.opencontainers.image.url=https://github.com/${{ github.repository }}
93+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
94+
org.opencontainers.image.vendor=${{ github.repository_owner }}
95+
8396
- name: 🔨 Build and push
8497
if: steps.tags.outputs.tags != ''
8598
uses: docker/build-push-action@v6
8699
with:
87100
context: .
88101
platforms: linux/amd64,linux/arm64
89-
push: ${{ !inputs.dry_run }}
102+
push: ${{ !inputs.dry_run && github.event_name != 'pull_request' }}
90103
tags: ${{ steps.tags.outputs.tags }}
104+
labels: ${{ steps.meta.outputs.labels }}
91105
cache-from: type=gha
92106
cache-to: type=gha,mode=max
93-
labels: |
94-
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
95-
org.opencontainers.image.revision=${{ github.sha }}
96-
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
107+
build-args: |
108+
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
109+
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
110+
REVISION=${{ github.sha }}
97111
98112
- name: ⚠️ Warning if skipped
99113
if: steps.tags.outputs.tags == ''

.github/workflows/mirror.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ jobs:
4040
chmod 600 ~/.ssh/id_rsa
4141
ssh-keyscan codeberg.org >> ~/.ssh/known_hosts
4242
git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true
43-
git push mirror --mirror
43+
git push mirror --all
44+
git push mirror --tags

.github/workflows/tests.yml

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: 🧪 Run Tests
22

33
on:
4-
pull_request:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
56
push:
67
branches: [main]
8+
workflow_dispatch:
79

810
concurrency:
911
group: ci-${{ github.ref }}
@@ -14,6 +16,12 @@ permissions:
1416
id-token: write # For OIDC with Codecov
1517
checks: write # For test reporting
1618

19+
env:
20+
# PR context helpers for conditional logic
21+
IS_PR: ${{ github.event_name == 'pull_request_target' }}
22+
IS_FORK: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository }}
23+
HAS_BOT_TOKEN: ${{ secrets.BOT_TOKEN != '' }}
24+
1725
jobs:
1826
unit-tests:
1927
name: Unit Tests
@@ -22,7 +30,12 @@ jobs:
2230
NODE_OPTIONS: "--max_old_space_size=8192"
2331

2432
steps:
33+
# Secure checkout for external PRs
2534
- uses: actions/checkout@v4
35+
with:
36+
# For PRs from forks, check out the PR head to prevent token exposure
37+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
38+
2639
- uses: actions/setup-node@v4
2740
with:
2841
node-version: 22
@@ -33,6 +46,7 @@ jobs:
3346
id: test
3447
run: |
3548
npx vitest run \
49+
--coverage \
3650
--reporter=github-actions \
3751
--reporter=verbose \
3852
--reporter=junit \
@@ -51,7 +65,7 @@ jobs:
5165
path: test-result-unit.txt
5266

5367
- name: Upload coverage to Codecov
54-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
68+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository
5569
uses: codecov/codecov-action@v4
5670
with:
5771
token: ${{ secrets.CODECOV_TOKEN }}
@@ -64,20 +78,22 @@ jobs:
6478
- name: Unit Test Report
6579
id: unit-test-report
6680
uses: dorny/test-reporter@v1
67-
if: always()
81+
if: always() && (env.IS_FORK != 'true' || env.HAS_BOT_TOKEN == 'true')
6882
with:
6983
name: Unit Tests
7084
path: test-results.xml
7185
reporter: java-junit
7286
fail-on-error: false
87+
token: ${{ env.IS_FORK == 'true' && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
88+
continue-on-error: true
7389

7490
- name: Save unit test report data
7591
if: always()
7692
run: |
77-
echo "passed=${{ steps.unit-test-report.outputs.passed }}" > unit-report-data.txt
78-
echo "failed=${{ steps.unit-test-report.outputs.failed }}" >> unit-report-data.txt
79-
echo "skipped=${{ steps.unit-test-report.outputs.skipped }}" >> unit-report-data.txt
80-
echo "time=${{ steps.unit-test-report.outputs.time }}" >> unit-report-data.txt
93+
echo "passed=${{ steps.unit-test-report.outputs.passed || '0' }}" > unit-report-data.txt
94+
echo "failed=${{ steps.unit-test-report.outputs.failed || '0' }}" >> unit-report-data.txt
95+
echo "skipped=${{ steps.unit-test-report.outputs.skipped || '0' }}" >> unit-report-data.txt
96+
echo "time=${{ steps.unit-test-report.outputs.time || '0' }}" >> unit-report-data.txt
8197
8298
- name: Upload unit test report data
8399
if: always()
@@ -104,7 +120,12 @@ jobs:
104120
NODE_OPTIONS: "--max_old_space_size=8192"
105121

106122
steps:
123+
# Secure checkout for external PRs
107124
- uses: actions/checkout@v4
125+
with:
126+
# For PRs from forks, check out the PR head to prevent naughty people finding my token
127+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
128+
108129
- uses: actions/setup-node@v4
109130
with:
110131
node-version: 22
@@ -142,20 +163,22 @@ jobs:
142163
- name: API Test Report
143164
id: api-test-report
144165
uses: dorny/test-reporter@v1
145-
if: always()
166+
if: always() && (env.IS_FORK != 'true' || env.HAS_BOT_TOKEN == 'true')
146167
with:
147168
name: API Contract Tests
148169
path: api-test-results.xml
149170
reporter: java-junit
150171
fail-on-error: false
172+
token: ${{ env.IS_FORK == 'true' && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
173+
continue-on-error: true
151174

152175
- name: Save API test report data
153176
if: always()
154177
run: |
155-
echo "passed=${{ steps.api-test-report.outputs.passed }}" > api-report-data.txt
156-
echo "failed=${{ steps.api-test-report.outputs.failed }}" >> api-report-data.txt
157-
echo "skipped=${{ steps.api-test-report.outputs.skipped }}" >> api-report-data.txt
158-
echo "time=${{ steps.api-test-report.outputs.time }}" >> api-report-data.txt
178+
echo "passed=${{ steps.api-test-report.outputs.passed || '0' }}" > api-report-data.txt
179+
echo "failed=${{ steps.api-test-report.outputs.failed || '0' }}" >> api-report-data.txt
180+
echo "skipped=${{ steps.api-test-report.outputs.skipped || '0' }}" >> api-report-data.txt
181+
echo "time=${{ steps.api-test-report.outputs.time || '0' }}" >> api-report-data.txt
159182
160183
- name: Upload API test report data
161184
if: always()
@@ -175,7 +198,12 @@ jobs:
175198
NODE_OPTIONS: "--max_old_space_size=8192"
176199

177200
steps:
201+
# Secure checkout for external PRs
178202
- uses: actions/checkout@v4
203+
with:
204+
# For PRs from forks, check out the PR head to prevent token exposure
205+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
206+
179207
- uses: actions/setup-node@v4
180208
with:
181209
node-version: 22
@@ -219,20 +247,22 @@ jobs:
219247
- name: E2E Test Report
220248
id: e2e-test-report
221249
uses: dorny/test-reporter@v1
222-
if: always()
250+
if: always() && (env.IS_FORK != 'true' || env.HAS_BOT_TOKEN == 'true')
223251
with:
224252
name: E2E Tests
225253
path: e2e-results.xml
226254
reporter: java-junit
227255
fail-on-error: false
256+
token: ${{ env.IS_FORK == 'true' && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
257+
continue-on-error: true
228258

229259
- name: Save e2e test report data
230260
if: always()
231261
run: |
232-
echo "passed=${{ steps.e2e-test-report.outputs.passed }}" > e2e-report-data.txt
233-
echo "failed=${{ steps.e2e-test-report.outputs.failed }}" >> e2e-report-data.txt
234-
echo "skipped=${{ steps.e2e-test-report.outputs.skipped }}" >> e2e-report-data.txt
235-
echo "time=${{ steps.e2e-test-report.outputs.time }}" >> e2e-report-data.txt
262+
echo "passed=${{ steps.e2e-test-report.outputs.passed || '0' }}" > e2e-report-data.txt
263+
echo "failed=${{ steps.e2e-test-report.outputs.failed || '0' }}" >> e2e-report-data.txt
264+
echo "skipped=${{ steps.e2e-test-report.outputs.skipped || '0' }}" >> e2e-report-data.txt
265+
echo "time=${{ steps.e2e-test-report.outputs.time || '0' }}" >> e2e-report-data.txt
236266
237267
- name: Upload e2e test report data
238268
if: always()

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
"build:node": "DEPLOY_ENV='node' npm run build",
1717
"build:static": "DEPLOY_ENV='static' npm run build",
1818
"test": "vitest",
19-
"test:ui": "vitest --ui",
2019
"test:coverage": "vitest --coverage",
2120
"test:api": "vitest run --config tests/vitest.api.config.ts",
22-
"test:e2e": "playwright test",
23-
"test:e2e:ui": "playwright test --ui"
21+
"test:e2e": "playwright test"
2422
},
2523
"dependencies": {},
2624
"devDependencies": {

vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
'src/hooks.server.ts',
2121
'src/service-worker.ts'
2222
],
23+
reporter: ['text', 'lcov', 'html'],
2324
thresholds: {
2425
global: {
2526
statements: 85,

0 commit comments

Comments
 (0)