Files
mailflare/.github/workflows/deploy-update.yml
T
2026-06-18 23:24:27 +07:00

72 lines
2.4 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: Download latest release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
release_json="$(curl -fsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${UPDATE_SOURCE_REPOSITORY}/releases/latest")"
tarball_url="$(node -e 'const fs = require("fs"); const release = JSON.parse(fs.readFileSync(0, "utf8")); process.stdout.write(release.tarball_url);' <<< "${release_json}")"
mkdir -p /tmp/mailflare-release
curl -fsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
"${tarball_url}" \
-o /tmp/mailflare-release.tar.gz
tar -xzf /tmp/mailflare-release.tar.gz -C /tmp/mailflare-release --strip-components=1
rsync -a --delete \
--exclude ".git" \
--exclude ".github" \
--exclude "node_modules" \
--exclude ".dev.vars" \
--exclude "wrangler.jsonc" \
/tmp/mailflare-release/ ./
- 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: Commit update
run: |
set -euo pipefail
if [ -z "$(git status --porcelain)" ]; then
echo "Repository is already up to date."
exit 0
fi
git config user.name "mailflare-update"
git config user.email "mailflare-update@users.noreply.github.com"
git add --all
git commit -m "chore: update Mailflare to latest release"
git push origin "HEAD:${GITHUB_REF_NAME}"