Github Action脚本用于将Yew应用程序与Trunk部署到Firebase的必要步骤是什么?

huangapple go评论51阅读模式
英文:

What steps does a Github Action Script for deploying Yew Apps with Trunk to Firebase has to have?

问题

我遇到的问题是,我很难弄清楚如何为Firebase Github操作的yml文件设置正确的部署脚本。

英文:

The issue I was facing, was that I had a hard time figuring out how to set up the correct deploy script for the Firebase Github action yml file.

答案1

得分: 1

以下是翻译好的内容:

1. 设置Rust工具链以正确的编译目标

为了使最终的trunk命令能够运行,您必须在执行服务器上安装Rust和Cargo。最简单的方法是使用工具链。根据别人的建议,我选择了这个工具链

这个工具链将确保安装Rust和Cargo。此外,您必须指定所需的编译目标。您可能还记得在配置Yew应用程序时运行了以下命令:

rustup target add wasm32-unknown-unknown

快速提醒,引用了Yew的文档

Rust可以编译不同“目标”(例如,不同的处理器)的源代码。用于基于浏览器的WebAssembly的编译目标称为wasm32-unknown-unknown。以下命令将向您的开发环境添加WebAssembly目标。

这意味着当工具链运行时,我们希望指定我们希望它稍后实现的编译目标,这是通过设置“targets”字段上的给定目标来完成的。最终,此第一步的代码如下所示:

# 提供的Rust工具链的名称+工具链规范,这里 => "@stable"
uses: dtolnay/rust-toolchain@stable
with:
  # 具有相应编译目标的提到的目标字段
  targets: wasm32-unknown-unknown

2. 安装trunk

就像您在本地环境中设置了trunk一样,我们需要在这里执行相同的操作。

run: cargo install trunk

3. 构建命令

最后但并非最不重要,提供构建命令。Yew文档提到:“当您准备发布应用程序时,只需运行trunk build --release。”

注意:如果您因某种原因尝试使用trunk serve --release,请不要这样做...

run: trunk build --release

4. 最后说明

将这些命令组合在一起时,正确缩进很重要!我们还将为每个步骤添加一个单独的“- name:”标签,声明当前操作。因此,我们的步骤部分最终将如下所示:

...
    runs-on: ubuntu-latest
# 步骤部分
    steps:
      - uses: actions/checkout@v3
      - name: 设置Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
          toolchain: stable
      - name: 安装Trunk
        run: cargo install trunk
      - name: 构建和部署
        run: trunk build --release
# 自动生成文件的其余部分
      - name: 部署到Firebase托管
        ...

希望这对任何人都有所帮助!

英文:

A Script that performs this has to have, except the standard one, the following steps:

<font size=4>1. Set up the rust toolchain with the correct compile target</font>

In order for the final trunk command to work, you must install rust and cargo on the executing server. The easiest way of doing this is using a toolchain. By someone else's recommendation, I settled with this one.

This toolchain will make sure that rust and cargo will be installed. Additionally, you have to specify your desired compile target. You may remember when you configured your Yew-app that you ran this command:

rustup target add wasm32-unknown-unknown

A quick reminder, citing the yew docs:

<sub>Rust can compile source codes for different "targets" (e.g. different processors). The compilation target for browser-based WebAssembly is called wasm32-unknown-unknown. The following command will add the WebAssembly target to your development environment.</sub>

This means when the toolchain runs, we want to specify what compile-target we want it later to implement, this is done by setting the given target on the "targets" field. In the end, the code for this first step looks like this:

# name of the provided rust toolchain + the toolchain specifier, here =&gt; &quot;@stable&quot;
uses: dtolnay/rust-toolchain@stable
with:
  # the mentioned target field with the corresponding compile-target
  targets: wasm32-unknown-unknown

<font size=4>2. Install trunk</font>

Like you set up your local environment with trunk, we need to do the same here.

run: cargo install trunk

<font size=4>3. Build command</font>

Last but not least, provide the build command. The Yew docs mention: "When you're ready to release your app, you can just run trunk build --release."

Note: If you are for some reason tempted: don't use trunk serve --release...

run: trunk build --release

<font size=4>4. Final Notes</font>

When packing those commands together it is important to get the indentation right! We will also add for every step a separate "- name:" tag, declaring the current operation. So our steps section will finally look like this:

...
    runs-on: ubuntu-latest
# step section
    steps:
      - uses: actions/checkout@v3
      - name: Set up Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
          toolchain: stable
      - name: Install Trunk
        run: cargo install trunk
      - name: Build and Deploy
        run: trunk build --release
# rest of the auto-generated file
      - name: Deploy to Firebase Hosting
        ...

Hope that helps anyone!

huangapple
  • 本文由 发表于 2023年7月7日 06:28:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632881.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定