name: Lint on: push: branches: ["**"] pull_request: branches: ["**"] jobs: php-lint: name: PHP (phpcs PSR-12) runs-on: ubuntu-latest steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - name: Install PHP and phpcs run: | apt-get update -qq apt-get install -y -qq php-cli php-xml curl -sL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -o /usr/local/bin/phpcs chmod +x /usr/local/bin/phpcs - name: Run phpcs run: phpcs --standard=.phpcs.xml . js-lint: name: JS (eslint) runs-on: ubuntu-latest steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - name: Install ESLint run: npm install --save-dev eslint@8 - name: Run ESLint run: npx eslint assets/js/ requirements: name: PHP requirements (version + extensions) runs-on: ubuntu-latest steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - name: Install PHP with required extensions run: | apt-get update -qq # Install the extensions declared in config/requirements.php so the # check verifies they are actually installable + loadable, and so this # build fails if a required extension can't be provided. apt-get install -y -qq php-cli php-ldap php-mysql php-curl php-mbstring - name: Verify runtime requirements run: php scripts/check_requirements.php ui: name: UI (playwright) runs-on: ubuntu-latest timeout-minutes: 30 # Official image with Chromium and its system libraries; its version must # match @playwright/test in tests/ui/package.json. container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: persist-credentials: false # no job pushes; keep the token out of .git/config - name: Install PHP and MariaDB run: tests/ui/setup.sh - name: Start Tinker Tickets (port 8400, seeded test data) run: tests/ui/stack.sh . 8400 tinker_ui - name: Install Playwright (lockfile only) working-directory: tests/ui run: npm ci - name: Run Playwright (desktop and mobile) working-directory: tests/ui run: npx playwright test - name: Server log if: always() run: tail -n 200 .ui-stack/server.log || true - name: Upload report, traces and screenshots if: failure() uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 (v4 is unsupported on Gitea) with: name: playwright-report path: | tests/ui/playwright-report/ tests/ui/test-results/ retention-days: 14 ui-screenshots: name: UI screenshots (before/after) runs-on: ubuntu-latest timeout-minutes: 30 if: github.event_name == 'pull_request' container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f env: BASE_SHA: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: persist-credentials: false # no job pushes; keep the token out of .git/config fetch-depth: 0 - name: Did this PR change the UI? id: ui run: | git config --global --add safe.directory "$PWD" if git diff --quiet "$BASE_SHA" HEAD -- assets/ views/; then echo "No UI files changed; no screenshots needed." else echo "changed=true" >> "$GITHUB_OUTPUT" fi - name: Install PHP and MariaDB if: steps.ui.outputs.changed == 'true' run: tests/ui/setup.sh - name: Start this PR's Tinker Tickets (port 8400) if: steps.ui.outputs.changed == 'true' run: tests/ui/stack.sh . 8400 tinker_ui - name: Start the base branch's Tinker Tickets (port 8401) if: steps.ui.outputs.changed == 'true' run: | git worktree add /tmp/base "$BASE_SHA" tests/ui/stack.sh /tmp/base 8401 tinker_ui_base - name: Capture before/after screenshots if: steps.ui.outputs.changed == 'true' run: | (cd tests/ui && npm ci) node tests/ui/screenshots.js ui-screenshots before=http://127.0.0.1:8401 after=http://127.0.0.1:8400 - name: Upload screenshots if: steps.ui.outputs.changed == 'true' uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 (v4 is unsupported on Gitea) with: name: ui-screenshots path: ui-screenshots/ retention-days: 30 deploy: name: Deploy runs-on: ubuntu-latest needs: [php-lint, js-lint, requirements, ui] if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development') permissions: contents: write steps: - name: Trigger webhook env: WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} GIT_REF: ${{ github.ref }} run: | if [ "$GIT_REF" = "refs/heads/main" ]; then HOOK_ID="tinker-deploy" else HOOK_ID="tinker-beta-deploy" fi PAYLOAD="{\"ref\":\"${GIT_REF}\"}" SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | awk '{print $2}') curl -sf --connect-timeout 10 \ -X POST \ -H "Content-Type: application/json" \ -H "X-Gitea-Signature: ${SIG}" \ -d "$PAYLOAD" \ "http://10.10.10.45:9000/hooks/${HOOK_ID}" - name: Tag deployed commit if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TAG="deploy-$(date -u +%Y.%m.%d)-${{ github.run_number }}" curl -sf -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"${TAG}\",\"target\":\"${{ github.sha }}\",\"message\":\"Deployed to production\"}" \ "https://code.lotusguild.org/api/v1/repos/${{ github.repository }}/tags" notify-failure: name: Notify on failure runs-on: ubuntu-latest needs: [php-lint, js-lint, requirements, ui] if: failure() && github.event_name == 'push' steps: - name: Send Matrix alert env: MATRIX_WEBHOOK_URL: ${{ secrets.MATRIX_WEBHOOK_URL }} REPO: ${{ github.repository }} BRANCH: ${{ github.ref_name }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | if [ -z "$MATRIX_WEBHOOK_URL" ] || [ "$MATRIX_WEBHOOK_URL" = "CONFIGURE_ME" ]; then exit 0; fi curl -sf -X POST "$MATRIX_WEBHOOK_URL" \ -H "Content-Type: application/json" \ -d "{\"text\":\"CI FAILED: ${REPO} @ ${BRANCH} — ${RUN_URL}\"}"