Initial commit - WIP

This commit is contained in:
2026-02-18 22:49:54 +01:00
commit bd58cbb1df
5 changed files with 297 additions and 0 deletions

17
info/test-headers.txt Normal file
View File

@@ -0,0 +1,17 @@
Host: api.efforting.tech
Content-Type: application/json
X-GitHub-Delivery: <DELIVERY_ID>
X-GitHub-Event: push
X-GitHub-Event-Type: push
X-GitHub-Hook-Installation-Target-Type: repository
X-Gitea-Delivery: <DELIVERY_ID>
X-Gitea-Event: push
X-Gitea-Event-Type: push
X-Gitea-Hook-Installation-Target-Type: repository
X-Gitea-Signature: <SIGNATURE>
X-Gogs-Delivery: <DELIVERY_ID>
X-Gogs-Event: push
X-Gogs-Event-Type: push
X-Gogs-Signature: <SIGNATURE>
X-Hub-Signature: sha1=bec69c38f0906f859227a8d265c3c9ed354e60f0
X-Hub-Signature-256: sha256=<SIGNATURE>

194
info/test-payload.json Normal file
View File

@@ -0,0 +1,194 @@
{
"ref": "refs/heads/main",
"before": "0000000000000000000000000000000000000000",
"after": "0000000000000000000000000000000000000000",
"compare_url": "https://gitea.efforting.tech/mikael-lovqvist/websperiments/compare/0000000000000000000000000000000000000000...0000000000000000000000000000000000000000",
"commits": [
{
"id": "0000000000000000000000000000000000000000",
"message": "This is a fake commit",
"url": "https://gitea.efforting.tech/mikael-lovqvist/websperiments/commit/0000000000000000000000000000000000000000",
"author": {
"name": "Ghost",
"email": "",
"username": ""
},
"committer": {
"name": "Ghost",
"email": "",
"username": ""
},
"verification": null,
"timestamp": "0001-01-01T00:00:00Z",
"added": null,
"removed": null,
"modified": null
}
],
"total_commits": 1,
"head_commit": {
"id": "0000000000000000000000000000000000000000",
"message": "This is a fake commit",
"url": "https://gitea.efforting.tech/mikael-lovqvist/websperiments/commit/0000000000000000000000000000000000000000",
"author": {
"name": "Ghost",
"email": "",
"username": ""
},
"committer": {
"name": "Ghost",
"email": "",
"username": ""
},
"verification": null,
"timestamp": "0001-01-01T00:00:00Z",
"added": null,
"removed": null,
"modified": null
},
"repository": {
"id": 5,
"owner": {
"id": 1,
"login": "mikael-lovqvist",
"login_name": "",
"source_id": 0,
"full_name": "",
"email": "mikael-lovqvist@noreply@gitea.efforting.tech",
"avatar_url": "https://gitea.efforting.tech/avatars/026f0fc4a56b9fd09a8c4a9f1f9d99c9d5369ac8452f0a83811989dfec27763b",
"html_url": "https://gitea.efforting.tech/mikael-lovqvist",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2026-02-10T22:26:01Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 1,
"following_count": 2,
"starred_repos_count": 0,
"username": "mikael-lovqvist"
},
"name": "websperiments",
"full_name": "mikael-lovqvist/websperiments",
"description": "Various experiments, some vibe coded, none well written. Quick demonstrations, starting off points, inspiration. Mostly for fun!",
"empty": false,
"private": true,
"fork": false,
"template": false,
"mirror": false,
"size": 285,
"language": "",
"languages_url": "https://gitea.efforting.tech/api/v1/repos/mikael-lovqvist/websperiments/languages",
"html_url": "https://gitea.efforting.tech/mikael-lovqvist/websperiments",
"url": "https://gitea.efforting.tech/api/v1/repos/mikael-lovqvist/websperiments",
"link": "",
"ssh_url": "git@gitea.efforting.tech:mikael-lovqvist/websperiments.git",
"clone_url": "https://gitea.efforting.tech/mikael-lovqvist/websperiments.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "main",
"archived": false,
"created_at": "2026-02-14T22:24:05Z",
"updated_at": "2026-02-14T22:25:09Z",
"archived_at": "1970-01-01T00:00:00Z",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"has_code": true,
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"projects_mode": "all",
"has_releases": true,
"has_packages": true,
"has_actions": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"allow_fast_forward_only_merge": true,
"allow_rebase_update": true,
"allow_manual_merge": false,
"autodetect_manual_merge": false,
"default_delete_branch_after_merge": false,
"default_merge_style": "merge",
"default_allow_maintainer_edit": false,
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"object_format_name": "sha1",
"mirror_updated": "0001-01-01T00:00:00Z",
"topics": [],
"licenses": []
},
"pusher": {
"id": 1,
"login": "mikael-lovqvist",
"login_name": "",
"source_id": 0,
"full_name": "",
"email": "mikael-lovqvist@noreply@gitea.efforting.tech",
"avatar_url": "https://gitea.efforting.tech/avatars/026f0fc4a56b9fd09a8c4a9f1f9d99c9d5369ac8452f0a83811989dfec27763b",
"html_url": "https://gitea.efforting.tech/mikael-lovqvist",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2026-02-10T22:26:01Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 1,
"following_count": 2,
"starred_repos_count": 0,
"username": "mikael-lovqvist"
},
"sender": {
"id": 1,
"login": "mikael-lovqvist",
"login_name": "",
"source_id": 0,
"full_name": "",
"email": "mikael-lovqvist@noreply@gitea.efforting.tech",
"avatar_url": "https://gitea.efforting.tech/avatars/026f0fc4a56b9fd09a8c4a9f1f9d99c9d5369ac8452f0a83811989dfec27763b",
"html_url": "https://gitea.efforting.tech/mikael-lovqvist",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2026-02-10T22:26:01Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 1,
"following_count": 2,
"starred_repos_count": 0,
"username": "mikael-lovqvist"
}
}

6
package.json Normal file
View File

@@ -0,0 +1,6 @@
{
"dependencies": {
"crypto": "^1.0.1",
"express": "^5.2.1"
}
}

43
t1.mjs Normal file
View File

@@ -0,0 +1,43 @@
import express from 'express'
import crypto from 'crypto'
import { writeFileSync } from 'fs'
const app = express()
const PORT = 4000
// Use raw body so HMAC matches exact bytes sent by Gitea
app.use(express.raw({ type: 'application/json' }))
const SECRET = 'somesecret'
app.post('/gitea/deploy', (req, res) => {
const signatureHeader = req.get('X-Hub-Signature-256')
if (!signatureHeader) {
return res.status(400).send('Missing signature')
}
//console.log(req.headers);
const expected = 'sha256=' + crypto
.createHmac('sha256', SECRET)
.update(req.body)
.digest('hex')
const sigBuf = Buffer.from(signatureHeader)
const expBuf = Buffer.from(expected)
//writeFileSync('last-payload.bin', req.body);
//console.log("Stored payload as last-payload.bin")
if (sigBuf.length !== expBuf.length || !crypto.timingSafeEqual(sigBuf, expBuf)) {
return res.sendStatus(401);
}
res.status(202).end();
})
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})

37
test-deployment.mjs Normal file
View File

@@ -0,0 +1,37 @@
import { readFileSync } from 'node:fs';
const json = JSON.parse(readFileSync('test-payload.json'));
if (json.after.match(/^0+$/)) {
// This is test deployment - for now we will simply replace with 'HEAD'
}
console.log(json.after, json.repository.ssh_url);
// git --git-dir=/srv/docker/gitea.efforting.tech/gitea-data/git/repositories/mikael-lovqvist/websperiments.git worktree add /srv/deploy/<repo> <commit-sha>
// /srv/docker/gitea.efforting.tech/gitea-data/git/repositories/mikael-lovqvist/websperiments.git
/*
git clone --mirror /srv/docker/gitea.efforting.tech/gitea-data/git/repositories/mikael-lovqvist/websperiments.git
git --git-dir=/srv/docker/gitea.efforting.tech/gitea-data/git/repositories/mikael-lovqvist/websperiments.git archive refs/heads/main | tar -x -C /srv/http/sites.efforting.tech/mikael-lovqvist/websperiments
ubuntu@vps-a0ce290a:/srv/http/sites.efforting.tech$ sudo -u www-data mkdir -p mikael-lovqvist/websperiments
ubuntu@vps-a0ce290a:/srv/http/sites.efforting.tech$ sudo -u www-data git --git-dir=/srv/docker/gitea.efforting.tech/gitea-data/git/repositories/mikael-lovqvist/websperiments.git archive refs/heads/main | sudo -u www-data tar -x -C /srv/http/sites.efforting.tech/mikael-lovqvist/websperiments
*/