Skip to content

Commit

Permalink
ci: add release action
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Jan 14, 2024
1 parent 609ed81 commit 89ab61f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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: 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: ${{ 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: ${{ 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: Rename binaries
run: |
mv x86_64-unknown-linux-gnu mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-unknown-linux-gnu
mv x86_64-apple-darwin mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-apple-darwin
mv x86_64-pc-windows-msvc mdbook-embedify-${{ steps.get_version.outputs.VERSION }}-x86_64-pc-windows-msvc
- 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
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
2 changes: 1 addition & 1 deletion example/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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).*"
2 changes: 1 addition & 1 deletion example/src/global-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).*"
```
Expand Down
4 changes: 2 additions & 2 deletions example/src/local/announcement-banner.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- embed ignore begin -->

```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).*" %}
```

<!-- embed ignore end -->
Expand All @@ -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).*"
```
Expand Down
5 changes: 3 additions & 2 deletions templates/announcement-banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@
</div>

<script>
const localData = JSON.parse(localStorage.getItem("announcement-banner"));
const banner = document.querySelector(".announcement-banner");
const name = banner.getAttribute("data-name");
const message = banner.querySelector("p").textContent;
const localData = JSON.parse(localStorage.getItem("mdbook-announcement-banner"));

if (localData && localData.hide === true && localData.name === name) banner.remove();
else {
Expand All @@ -80,7 +81,7 @@
// add event listener to close button
banner.querySelector("button").addEventListener("click", () => {
banner.remove();
localStorage.setItem("announcement-banner", JSON.stringify({ name, hide: true }));
localStorage.setItem("mdbook-announcement-banner", JSON.stringify({ name, hide: true, message }));
});
}
</script>

0 comments on commit 89ab61f

Please sign in to comment.