Make local master canonical for build metadata
This commit is contained in:
@@ -6,46 +6,9 @@ on:
|
||||
- dev
|
||||
- master
|
||||
jobs:
|
||||
stamp_build:
|
||||
if: gitea.ref_name == 'master' && !contains(gitea.event.head_commit.message, '[skip ci]')
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Stamp composer build from origin/master
|
||||
env:
|
||||
SPEEDBB_REPO: ${{ vars.SPEEDBB_REPO }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_ACTOR: ${{ gitea.actor }}
|
||||
run: |
|
||||
set -e
|
||||
REPO="$SPEEDBB_REPO"
|
||||
if [ -n "$GITEA_TOKEN" ]; then
|
||||
REPO=$(echo "$SPEEDBB_REPO" | sed "s#https://#https://${GITEA_ACTOR}:${GITEA_TOKEN}@#")
|
||||
fi
|
||||
|
||||
git clone --quiet --branch=master "$REPO" repo
|
||||
cd repo
|
||||
git fetch origin master
|
||||
|
||||
BUILD="$(git rev-list --count origin/master)"
|
||||
CURRENT="$(php -r 'echo (string) ((json_decode(file_get_contents("composer.json"), true)["build"] ?? ""));')"
|
||||
|
||||
if [ "$CURRENT" = "$BUILD" ]; then
|
||||
echo "composer.json build already $BUILD; no changes."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
BUILD="$BUILD" php -r '$p="composer.json"; $d=json_decode(file_get_contents($p), true); if (!is_array($d)) { fwrite(STDERR, "Invalid composer.json\n"); exit(1);} $d["build"]=getenv("BUILD"); file_put_contents($p, json_encode($d, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES).PHP_EOL);'
|
||||
|
||||
git config user.name "speedbb-ci"
|
||||
git config user.email "ci@24unix.net"
|
||||
git add composer.json
|
||||
git commit -m "ci: sync composer build to ${BUILD} [skip ci]"
|
||||
git push origin master
|
||||
|
||||
deploy:
|
||||
if: gitea.ref_name == 'master' && !contains(gitea.event.head_commit.message, '[skip ci]')
|
||||
if: gitea.ref_name == 'master'
|
||||
runs-on: self-hosted
|
||||
needs: stamp_build
|
||||
steps:
|
||||
- name: Custom Checkout
|
||||
env:
|
||||
@@ -69,7 +32,7 @@ jobs:
|
||||
rm .vault_pass.txt
|
||||
|
||||
promote_stable:
|
||||
if: gitea.ref_name == 'master' && !contains(gitea.event.head_commit.message, '[skip ci]')
|
||||
if: gitea.ref_name == 'master'
|
||||
runs-on: self-hosted
|
||||
needs: deploy
|
||||
steps:
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Keep commits possible when local DB is offline.
|
||||
if ! php artisan version:fetch >/dev/null 2>&1; then
|
||||
echo "pre-commit: skipped 'php artisan version:fetch' (database unreachable)." >&2
|
||||
echo "pre-commit: start MySQL and run it manually when needed." >&2
|
||||
fi
|
||||
# Stamp composer.json build from local git commit count on master/HEAD.
|
||||
BUILD="$(git rev-list --count master 2>/dev/null || git rev-list --count HEAD)"
|
||||
|
||||
BUILD="$BUILD" php -r '
|
||||
$path = "composer.json";
|
||||
$data = json_decode(file_get_contents($path), true);
|
||||
if (!is_array($data)) {
|
||||
fwrite(STDERR, "pre-commit: invalid composer.json\n");
|
||||
exit(1);
|
||||
}
|
||||
$build = getenv("BUILD");
|
||||
if ($build === false || $build === "") {
|
||||
fwrite(STDERR, "pre-commit: missing BUILD value\n");
|
||||
exit(1);
|
||||
}
|
||||
$current = (string)($data["build"] ?? "");
|
||||
if ($current === $build) {
|
||||
exit(0);
|
||||
}
|
||||
$data["build"] = $build;
|
||||
file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
fwrite(STDOUT, "pre-commit: composer.json build updated to {$build}\n");
|
||||
'
|
||||
|
||||
Reference in New Issue
Block a user