Brand new CI/CD pipeline (hope this one works out this time)
This commit is contained in:
parent
1911024734
commit
b961b0852a
1 changed files with 66 additions and 17 deletions
|
|
@ -1,17 +1,38 @@
|
||||||
|
name: Build and deploy all
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
x-site-config: &site_matrix
|
||||||
|
include:
|
||||||
|
- site: "harbor"
|
||||||
|
dest: /var/www/harbor
|
||||||
|
secret_key: "CONFIG_HARBOR"
|
||||||
|
# - site: "atlantis"
|
||||||
|
# dest: /var/www/atlantis
|
||||||
|
# secret_key: "CONFIG_ATLANTIS"
|
||||||
|
# - site: "amiral"
|
||||||
|
# dest: /var/www/amiral
|
||||||
|
# secret_key: "CONFIG_AMIRAL"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
|
strategy:
|
||||||
|
matrix: *site_matrix
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout git repository
|
- name: Checkout git repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: "Install pnpm"
|
- name: Inject configs
|
||||||
|
env:
|
||||||
|
CONF: ${{ secrets[matrix.secret_key] }}
|
||||||
|
run: |
|
||||||
|
echo "$CONF" > src/data/content.json
|
||||||
|
|
||||||
|
- name: Install pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
|
|
@ -21,36 +42,64 @@ jobs:
|
||||||
with:
|
with:
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
- name: "Install dependencies"
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
- name: "Lint code"
|
- name: Lint code
|
||||||
run: pnpm run lint
|
run: pnpm run lint
|
||||||
|
|
||||||
- name: "Checking code format"
|
- name: Checking code format
|
||||||
run: pnpm run format:check
|
run: pnpm run format:check
|
||||||
|
|
||||||
- name: "Build the project"
|
- name: Build the project
|
||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
|
|
||||||
|
- name: Save the result for deployment
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-${{ matrix.site }}
|
||||||
|
path: dist/
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
|
strategy:
|
||||||
|
matrix: *site_matrix
|
||||||
steps:
|
steps:
|
||||||
- name: Get current date
|
|
||||||
id: date
|
|
||||||
run: echo "::set-output name=date::$(date +'%Y%m%d%H%M%S')"
|
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
chmod 0700 ~/.ssh
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
echo "${{ secrets.SSHPRIVKEY }}" > ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_rsa
|
||||||
chmod 0600 ~/.ssh/id_ed25519
|
ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
|
||||||
echo "[${{ vars.WEBSERVER_IP }}]:${{ SSHPORT }} ${{ secrets.SSHPUBKEY }}" > ~/.ssh/known_hosts
|
|
||||||
chmod 0600 ~/.ssh/known_hosts
|
|
||||||
- name: Push
|
- name: Push
|
||||||
run: |
|
run: |
|
||||||
scp -P ${{ secrets.SSHPORT }} -r dist ${{ secrets.SSH_USERNAME }}@${{ vars.WEBSERVER_IP }}:~/oblog-parallels/build-${{ steps.date.outputs.date }}
|
rsync -avz -e "ssh -p ${{ secrets.SERVER_PORT }}" --delete ./dist/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ matrix.dest }}
|
||||||
- name: Update symlink
|
|
||||||
run: |
|
notify:
|
||||||
ssh ${{ secrets.SSH_USERNAME }}@${{ vars.WEBSERVER_IP }} -p ${{ secrets.SSHPORT }} "cp -r ~/oblog-parallels/build-${{ steps.date.outputs.date }} ~/oblog-parallels/dist"
|
needs: deploy
|
||||||
|
runs-on: docker
|
||||||
|
if: always() # Always run
|
||||||
|
steps:
|
||||||
|
- name: Send Discord Notification
|
||||||
|
uses: appleboy/discord-action@master
|
||||||
|
with:
|
||||||
|
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
|
||||||
|
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
|
||||||
|
color: ${{ needs.deploy.result == 'success' && '48867' || '16711680' }}
|
||||||
|
message: |
|
||||||
|
**Deployment Report**
|
||||||
|
**Status:** ${{ needs.deploy.result }}
|
||||||
|
**Repo:** ${{ gitea.repository }}
|
||||||
|
**Commit:** ${{ gitea.sha }}
|
||||||
|
|
||||||
|
# For later
|
||||||
|
# - name: Send Matrix Notification
|
||||||
|
# uses: s707/matrix-action@master
|
||||||
|
# with:
|
||||||
|
# server_url: https://matrix.org
|
||||||
|
# room_id: ${{ secrets.MATRIX_ROOM_ID }}
|
||||||
|
# access_token: ${{ secrets.MATRIX_ACCESS_TOKEN }}
|
||||||
|
# message: "Deployment of ${{ gitea.repository }} finished with status: ${{ needs.deploy.result }}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue