From 7ad2fa8a9af64f7389402bba6f2bcbc1d6e2df48 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Wed, 11 Oct 2023 10:35:44 +0800 Subject: [PATCH] ci: add build gh-pages workflow --- .github/workflows/get-melt-changed.yml | 35 ++++++++++++++++++++ .github/workflows/gh-pages.yml | 45 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/get-melt-changed.yml create mode 100644 .github/workflows/gh-pages.yml diff --git a/.github/workflows/get-melt-changed.yml b/.github/workflows/get-melt-changed.yml new file mode 100644 index 0000000..6da181c --- /dev/null +++ b/.github/workflows/get-melt-changed.yml @@ -0,0 +1,35 @@ +name: Get Melt Changed Call + +on: + workflow_call: + outputs: + melt_changed: + description: "Melt Changed" + value: ${{ jobs.create.outputs.melt_changed }} + +jobs: + create: + name: Detect Source Change + runs-on: ubuntu-latest + outputs: + melt_changed: ${{ steps.set-source-changed.outputs.melt_changed }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get source files that changed + id: changed-source + uses: tj-actions/changed-files@v36 + with: + files: | + gh-pages + src + Cargo.toml + + - name: List source files that changed + run: echo '${{ steps.changed-source.outputs.all_changed_files }}' + + - name: Set melt_changed + id: set-source-changed + run: | + echo "melt_changed=${{ steps.changed-source.outputs.any_changed }}" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 0000000..0d5dda7 --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,45 @@ +name: Build gh-pages + +on: + schedule: + - cron: "0 23 * * *" + +jobs: + get-melt-changed: + uses: ./.github/workflows/get-melt-changed.yml + deploy: + runs-on: ubuntu-latest + needs: [get-melt-changed] + if: needs.get-melt-changed.outputs.melt_changed == 'true' + permissions: + contents: write # To push a branch + pull-requests: write # To create a PR from that branch + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + override: true + - name: Install Trunk + uses: jetli/trunk-action@v0.4.0 + with: + version: "latest" + - name: Deploy GitHub Pages + run: | + cd gh-pages + trunk build --release + git worktree add gh-pages + git config user.name "Deploy demo from CI" + git config user.email "" + cd gh-pages + # Delete the ref to avoid keeping history. + git update-ref -d refs/heads/gh-pages + rm -rf * + mv ../docs/* . + git add . + git commit -m "Deploy demo $GITHUB_SHA to gh-pages" + git push --force --set-upstream origin gh-pages