134 lines
3.9 KiB
YAML
134 lines
3.9 KiB
YAML
name: Release package
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
release:
|
|
permissions:
|
|
contents: write
|
|
issues: write
|
|
pull-requests: write
|
|
id-token: write
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Install dependencies with Proxy
|
|
env:
|
|
http_proxy: "http://host.docker.internal:3142"
|
|
https_proxy: "http://host.docker.internal:3142"
|
|
run: |
|
|
# Kiểm tra proxy có hoạt động không
|
|
echo "Acquire::http::Proxy \"$http_proxy\";" > /etc/apt/apt.conf.d/80proxy
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends --no-install-suggests \
|
|
docker-cli zip docker-buildx
|
|
|
|
- name: Setup SSH Key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
|
|
ssh-keyscan -t ed25519 vps.demonkernel.io.vn >> ~/.ssh/known_hosts
|
|
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- uses: pnpm/action-setup@v3
|
|
with:
|
|
version: 10.9.0
|
|
run_install: false
|
|
|
|
- name: Get pnpm store directory
|
|
shell: bash
|
|
run: |
|
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
|
|
- name: Setup pnpm cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ env.STORE_PATH }}
|
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-store-
|
|
|
|
- name: Update dependencies
|
|
run: pnpm update
|
|
|
|
- name: Format code
|
|
run: pnpm format
|
|
|
|
- name: Build application
|
|
run: pnpm build
|
|
|
|
- name: Release
|
|
env:
|
|
GITEA_USER: ${{ github.actor }}
|
|
GITEA_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
|
run: pnpm release
|
|
|
|
- name: Set Version Output
|
|
id: set_output
|
|
run: |
|
|
# Đọc version hiện tại trong package.json sau khi release
|
|
VERSION=$(node -p "require('./package.json').version")
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
if: gitea.ref == 'refs/heads/main'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: vps.demonkernel.io.vn
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.ACCESS_TOKEN }}
|
|
|
|
- name: Prepare Docker Metadata
|
|
id: meta
|
|
run: |
|
|
# Lowercase Repository
|
|
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
RAW_VERSION="${{ steps.set_output.outputs.version }}"
|
|
VERSION_LOWER=$(echo "$RAW_VERSION" | tr '[:upper:]' '[:lower:]')
|
|
|
|
echo "repo=$REPO_LOWER" >> $GITHUB_OUTPUT
|
|
echo "version=$VERSION_LOWER" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
push: ${{ github.ref_name == 'main' }}
|
|
tags: |
|
|
vps.demonkernel.io.vn/${{ steps.meta.outputs.repo }}:latest
|
|
vps.demonkernel.io.vn/${{ steps.meta.outputs.repo }}:${{ steps.meta.outputs.version }}
|
|
|
|
- name: Commit & Push Changes
|
|
run: |
|
|
if [ -n "$(git status --porcelain)" ]&& [ "${{ github.ref_name }}" = "main" ]; then
|
|
git config --global user.name "gitea-actions"
|
|
git config --global user.email "actions-user@noreply.git.demonkernel.io.vn"
|
|
|
|
REPO_NAME="${{ gitea.repository }}"
|
|
|
|
git remote set-url origin ssh://git@vps.demonkernel.io.vn/${REPO_NAME}.git
|
|
|
|
git rm -r --cached .
|
|
git add .
|
|
git commit -m "chore: release [ci skip]"
|
|
|
|
git push
|
|
fi
|