From b616ca2cc65f05b1cb03935f2bae0633c3c8e208 Mon Sep 17 00:00:00 2001 From: slhmy <31381093+slhmy@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:00:03 +0800 Subject: [PATCH] Add release build action (#25) * Add release build action * Add check on main PR * Fix * Adjust action name * Fix * Add condition --- .github/workflows/release-build.yml | 63 +++++++++++++++++++++++++++++ .gitignore | 1 + RELEASE_INFO.yml | 4 ++ package.json | 1 + 4 files changed, 69 insertions(+) create mode 100644 .github/workflows/release-build.yml create mode 100644 RELEASE_INFO.yml diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 000000000..db0b136fd --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,63 @@ +name: Build and Release + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install tools + run: | + sudo apt-get update + sudo apt-get install -y zip + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Read Release Info + id: read_release_info + uses: actions/github-script@v4 + with: + script: | + const fs = require('fs'); + const yaml = require('js-yaml'); + + const releaseInfo = yaml.load(fs.readFileSync('RELEASE_INFO.yml', 'utf8')); + + return releaseInfo; + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release + if: github.event_name == 'push' + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.read_release_info.outputs.tag_name }} + release_name: ${{ steps.read_release_info.outputs.release_name }} + body: ${{ steps.read_release_info.outputs.description }} + + - name: Upload Release Asset + if: github.event_name == 'push' + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist.zip + asset_name: dist.zip + asset_content_type: application/zip diff --git a/.gitignore b/.gitignore index 800f3a80c..84cde4705 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # production /build /dist +dist.zip # misc .DS_Store diff --git a/RELEASE_INFO.yml b/RELEASE_INFO.yml new file mode 100644 index 000000000..cd6d729c9 --- /dev/null +++ b/RELEASE_INFO.yml @@ -0,0 +1,4 @@ +tag_name: v0.0.1 +release_name: Release v0.0.1 +body: | + This release is automatically generated. diff --git a/package.json b/package.json index cf8475bdc..7bf88cd0f 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "start": "vite", "start-mock": "vite --mode mock", "build": "vite build", + "build-and-zip": "vite build && zip -r dist.zip dist", "init-mock": "npx msw init public --no-save", "prettier": "npx prettier --write \"src/**/*.{ts,tsx}\"", "prettier:check": "npx prettier --check \"src/**/*.{ts,tsx}\"",