ci: deploy using railway cli #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π Deploy | |
on: | |
push: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
deploy: | |
name: π Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v4 | |
- name: β Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: π₯ Install dependencies | |
run: npm i -g @railway/cli | |
- name: π Deploy | |
run: railway up | |
env: | |
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} | |
purge: | |
name: β»οΈ Purge Cloudflare cache | |
runs-on: ubuntu-latest | |
needs: deploy | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: β Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: π₯ Install dependencies | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
run_install: | | |
- recursive: true | |
args: [--frozen-lockfile, --strict-peer-dependencies] | |
- name: π¦ Build current commit | |
run: | | |
pnpm run build | |
mv ./build ./current | |
- name: π¦ Build previous commit | |
run: | | |
git checkout HEAD^ | |
pnpm install --frozen-lockfile --strict-peer-dependencies | |
pnpm run build | |
mv ./build ./previous | |
- name: π Generate diff | |
id: diff | |
run: | | |
if [ -z "$(diff -qr ./current ./previous)" ]; then | |
echo "has_diff=false" >> $GITHUB_OUTPUT | |
else | |
echo "has_diff=true" >> $GITHUB_OUTPUT | |
fi | |
- name: β»οΈ Purge Cloudflare cache | |
uses: jakejarvis/cloudflare-purge-action@v0.3.0 | |
if: steps.diff.outputs.has_diff == 'true' | |
env: | |
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }} | |
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }} | |
PURGE_URLS: '["https://www.mcan.sh", "https://www.mcan.sh/resume", "https://www.mcan.sh/resume.pdf"]' |