Update workflow files

pull/18/head
maru 2024-03-26 20:50:44 -04:00
parent 28be258fbe
commit 03a3074209
No known key found for this signature in database
GPG Key ID: 37689350E9CD0F0D
2 changed files with 23 additions and 57 deletions

View File

@ -1,39 +0,0 @@
name: Build
on:
push: {}
pull_request: {}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
NODE_ENV: production
- name: Upload Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: "${{ github.event.repository.name }}-${{ github.sha }}"
path: dist
- name: Trigger Deployment
# only run on the main branch
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
with:
event-type: deploy-ssh
client-payload: |
{
"ref": "${{ github.ref }}",
"sha": "${{ github.sha }}",
"artifact-url": "${{ steps.upload-artifact.outputs.artifact-url }}",
"artifact-name": "${{ github.event.repository.name }}-${{ github.sha }}"
}

View File

@ -1,31 +1,36 @@
name: Deploy name: Deploy
on: on:
repository_dispatch: push: {}
types: [deploy-ssh] pull_request: {}
jobs: jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
ARTIFACT_NAME: ${{ github.event.client_payload.artifact-name }}
ARTIFACT_URL: ${{ github.event.client_payload.artifact-url }}
steps: steps:
- name: Deploy via SSH - uses: actions/checkout@v4
id: deploy - uses: actions/setup-node@v4
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with: with:
host: ${{ secrets.SSH_HOST }} node-version: "20"
username: ${{ secrets.SSH_USER }} - name: Install dependencies
key: ${{ secrets.SSH_PRIVATE_KEY }} run: npm ci
port: ${{ secrets.SSH_PORT }} - name: Build
script: | run: npm run build
cd ${{ secrets.TMP_DIR }} env:
wget -O "${{ env.ARTIFACT_NAME }}.zip" --header="Authorization: token ${{ github.token }}" ${{ env.ARTIFACT_URL }} NODE_ENV: production
unzip -aDo "${{ env.ARTIFACT_NAME }}.zip" -d "${{ env.ARTIFACT_NAME }}" - name: Set up SSH
rsync -vR --delete "${{ env.ARTIFACT_NAME }}/" "${{ secrets.DESTINATION_DIR }}" if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
rm -rf "./${{ env.ARTIFACT_NAME }}.zip" "./${{ env.ARTIFACT_NAME }}" run: |
mkdir ~/.ssh
echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/*
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy build on server
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
run: rsync -vrm dist/* ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.DESTINATION_DIR }}
- name: Purge Cloudflare Cache - name: Purge Cloudflare Cache
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
id: purge-cache id: purge-cache
uses: NathanVaughn/actions-cloudflare-purge@f70c63827b539cf48eb3a29fdaa7547eca4dede4 #latest commit at the time uses: NathanVaughn/actions-cloudflare-purge@f70c63827b539cf48eb3a29fdaa7547eca4dede4 #latest commit at the time
with: with: