2 Commits

+35 -52
View File
@@ -2,7 +2,7 @@ name: Build and Deploy
on: on:
release: release:
types: [published] types: [created]
jobs: jobs:
build: build:
@@ -16,7 +16,7 @@ jobs:
- name: Setup Node - name: Setup Node
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 24 node-version: 20
cache: pnpm cache: pnpm
- name: Setup pnpm - name: Setup pnpm
@@ -30,24 +30,12 @@ jobs:
- name: Build release archive - name: Build release archive
run: pnpm build:tar run: pnpm build:tar
- name: Upload artifact to server - name: Upload build artifact
uses: appleboy/scp-action@v0.1.7 uses: actions/upload-artifact@v4
with: with:
host: ${{ vars.DEPLOY_HOST }} name: dist-archive
username: ${{ vars.DEPLOY_USER }} path: dist.tar.gz
port: ${{ vars.DEPLOY_PORT }} retention-days: 1
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "dist.tar.gz"
target: "/tmp/build-artifact/"
- name: Move artifact to /tmp
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.DEPLOY_HOST }}
username: ${{ vars.DEPLOY_USER }}
port: ${{ vars.DEPLOY_PORT }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
command: mv /tmp/build-artifact/dist.tar.gz /tmp/dist.tar.gz && rm -rf /tmp/build-artifact
upload-release-asset: upload-release-asset:
name: Upload to Gitea Release name: Upload to Gitea Release
@@ -55,46 +43,41 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Download artifact from server - name: Download build artifact
env: uses: actions/download-artifact@v4
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }} with:
DEPLOY_USER: ${{ vars.DEPLOY_USER }} name: dist-archive
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: |
set -e
SSH_DIR="${RUNNER_TEMP}/ssh"
mkdir -p "$SSH_DIR"
chmod 700 "$SSH_DIR"
printf '%s\n' "$DEPLOY_SSH_KEY" > "$SSH_DIR/key"
chmod 600 "$SSH_DIR/key"
scp -i "$SSH_DIR/key" \
-P "$DEPLOY_PORT" \
-o StrictHostKeyChecking=accept-new \
-o UserKnownHostsFile="$SSH_DIR/known_hosts" \
"${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/dist.tar.gz" \
./dist.tar.gz
rm -rf "$SSH_DIR"
- name: Upload release asset via Gitea API - name: Upload release asset
run: | uses: https://gitea.com/actions/forgejo-release@v1
set -e with:
RELEASE_ID=$(jq -r '.release.id' "$GITEA_EVENT_PATH") direction: upload
URL="${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases/${RELEASE_ID}/assets?name=dist.tar.gz" files: dist.tar.gz
curl -fsSL \ env:
-X POST \ FORGEJO_TOKEN: ${{ secrets.GITEA_TOKEN }}
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/gzip" \
--data-binary "@dist.tar.gz" \
"${URL}"
deploy-to-server: deploy-to-server:
name: Deploy to onixbyte.cn name: Deploy to onixbyte.cn
needs: [build, upload-release-asset] needs: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Extract archive and deploy - name: Download build artifact
uses: actions/download-artifact@v4
with:
name: dist-archive
- name: Upload archive to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ vars.DEPLOY_HOST }}
username: ${{ vars.DEPLOY_USER }}
port: ${{ vars.DEPLOY_PORT }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "dist.tar.gz"
target: "/tmp/"
- name: Extract archive and set ownership
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
with: with:
host: ${{ vars.DEPLOY_HOST }} host: ${{ vars.DEPLOY_HOST }}