The workflow rsynced an upstream tarball over the checkout with --delete, discarding every local modification outside the excluded paths. Any fix applied to an installation was silently reverted and committed on the next update, including fixes to the update mechanism itself. It also fetched releases/latest, which 404s for a repository with no published releases, so the first step failed before doing anything. Fetch and merge the upstream default branch instead. This preserves local commits, matches the behaviour the README documents, drops the dependency on published releases, and fails loudly on conflict rather than discarding work. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
71 lines
2.3 KiB
YAML
71 lines
2.3 KiB
YAML
name: Dashboard Update
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
update:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
UPDATE_SOURCE_REPOSITORY: ${{ vars.UPDATE_SOURCE_REPOSITORY || 'hieunc229/mailflare' }}
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Merge upstream changes
|
|
run: |
|
|
set -euo pipefail
|
|
git config user.name "mailflare-update"
|
|
git config user.email "mailflare-update@users.noreply.github.com"
|
|
|
|
upstream_url="https://github.com/${UPDATE_SOURCE_REPOSITORY}.git"
|
|
if git remote get-url upstream >/dev/null 2>&1; then
|
|
git remote set-url upstream "${upstream_url}"
|
|
else
|
|
git remote add upstream "${upstream_url}"
|
|
fi
|
|
git fetch --no-tags upstream
|
|
|
|
upstream_branch="$(git remote show upstream | sed -n 's/.*HEAD branch: //p')"
|
|
if [ -z "${upstream_branch}" ]; then
|
|
echo "::error::Could not resolve the default branch of ${UPDATE_SOURCE_REPOSITORY}."
|
|
exit 1
|
|
fi
|
|
echo "Merging upstream/${upstream_branch} into ${GITHUB_REF_NAME}."
|
|
|
|
# A merge keeps local modifications instead of overwriting them, and
|
|
# stops on conflict rather than silently discarding local work.
|
|
if ! git merge --no-edit "upstream/${upstream_branch}"; then
|
|
git merge --abort || true
|
|
echo "::error::Merge conflict with upstream/${upstream_branch}. Resolve it locally and push."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "22"
|
|
|
|
- name: Install dependencies
|
|
run: npm install --no-package-lock
|
|
|
|
- name: Apply database migrations
|
|
run: npx wrangler d1 migrations apply DB --remote
|
|
|
|
- name: Push update
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "$(git log "origin/${GITHUB_REF_NAME}..HEAD" --oneline)" ]; then
|
|
echo "Repository is already up to date."
|
|
exit 0
|
|
fi
|
|
git push origin "HEAD:${GITHUB_REF_NAME}"
|