From a3163c7c8bc60060d15519dac5d61d100eb1ae2f Mon Sep 17 00:00:00 2001 From: Cael Date: Sun, 14 Jan 2024 14:39:22 +0800 Subject: [PATCH] ci: add release action --- .github/workflows/release.yaml | 93 ++++++++++++++++++++++++ example/book.toml | 2 +- example/src/global-configuration.md | 2 +- example/src/local/announcement-banner.md | 4 +- templates/announcement-banner.html | 5 +- 5 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9f1c5fa --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,93 @@ +name: release +on: + push: + tags: + - "*" + +jobs: + build: + strategy: + fail-fast: true + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: x86_64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@master + + - name: Cahce + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + override: true + toolchain: stable + target: ${{ matrix.target }} + + - name: Build release + run: cargo build --release + + - name: Artifact (Unix) + if: matrix.target != 'x86_64-pc-windows-msvc' + uses: actions/upload-artifact@v4 + with: + name: mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} + path: target/release/mdbook-embedify + + - name: Artifact (Windows) + if: matrix.target == 'x86_64-pc-windows-msvc' + uses: actions/upload-artifact@v4 + with: + name: mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} + path: target/release/mdbook-embedify.exe + + release: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/download-artifact@v4 + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + + - name: Install packages + run: sudo apt update && sudo apt install -y upx-ucl zip + + - name: Compress binaries + run: | + ls -lh mdbook-embedify-*/mdbook-embedify* + chmod u+x mdbook-embedify-*/mdbook-embedify* + upx --lzma --best mdbook-embedify-*/mdbook-embedify* + zip -r mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-unknown-linux-gnu{.zip,} + zip -r mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-apple-darwin{.zip,} + zip -r mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-pc-windows-msvc{.zip,} + + - name: Create release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + name: v${{ steps.get_version.outputs.VERSION }} + files: | + mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-unknown-linux-gnu.zip + mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-apple-darwin.zip + mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-pc-windows-msvc.zip diff --git a/example/book.toml b/example/book.toml index 82de152..01e971c 100644 --- a/example/book.toml +++ b/example/book.toml @@ -54,6 +54,6 @@ copy-js = true scroll-to-top.enable = true announcement-banner.enable = true -announcement-banner.name = "v0.1.0" +announcement-banner.name = "0.2.1" announcement-banner.style = "default" announcement-banner.message = "*Version **0.2.1** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.1).*" diff --git a/example/src/global-configuration.md b/example/src/global-configuration.md index d5e3ae7..61461b3 100644 --- a/example/src/global-configuration.md +++ b/example/src/global-configuration.md @@ -24,7 +24,7 @@ Below is a full list of apps that support this feature: scroll-to-top.enable = true announcement-banner.enable = true -announcement-banner.name = "v0.1.0" +announcement-banner.name = "0.2.1" announcement-banner.style = "default" announcement-banner.message = "*Version **0.2.1** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.1).*" ``` diff --git a/example/src/local/announcement-banner.md b/example/src/local/announcement-banner.md index a36a32a..9a1411d 100644 --- a/example/src/local/announcement-banner.md +++ b/example/src/local/announcement-banner.md @@ -11,7 +11,7 @@ ```text -{% embed announcement-banner name="v0.1.0" style="default" message="*Version **0.2.1** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.1).*" %} +{% embed announcement-banner name="0.2.1" style="default" message="*Version **0.2.1** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.1).*" %} ``` @@ -23,7 +23,7 @@ However, you may want to enable it for the whole book. You can do this by adding ```toml [preprocessor.embedify] announcement-banner.enable = true -announcement-banner.name = "v0.1.0" +announcement-banner.name = "0.2.1" announcement-banner.style = "default" announcement-banner.message = "*Version **0.2.1** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.1).*" ``` diff --git a/templates/announcement-banner.html b/templates/announcement-banner.html index b0e7424..eeb9e5c 100644 --- a/templates/announcement-banner.html +++ b/templates/announcement-banner.html @@ -67,9 +67,10 @@