跳到主内容
Rust
文章阅读

Rust使用Github action自动编译并发行Release版本

2025/12/1699 次阅读4 分钟

这里需要用到taiki-e/create-gh-release-action@v1这个action,可以到Github action市场下载和查看相关文档

1.编写 rust-build.yml构建配置


name: Release
permissions:
  contents: write
on:
  push:
    tags:
      - v[0-9]+.*  #新建tag触发,比如v0.1.1
jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: cross-compile-action #分支名字
      - uses: taiki-e/create-gh-release-action@v1
        with:
          changelog: CHANGELOG.md #获取更新日志,需要在changelog添加对应版本的更新日志,否则会失败
          token: ${{ secrets.ACTION_ACCESS }} # github token
  upload-assets:
    needs: create-release
    strategy:
      matrix:
        include: #编译的平台tager
          - target: aarch64-unknown-linux-gnu
          - target: aarch64-unknown-linux-musl
          - target: aarch64-apple-darwin
            os: macos-11
          - target: x86_64-unknown-linux-gnu
          - target: x86_64-unknown-linux-musl
          - target: x86_64-apple-darwin
            os: macos-10.15
          - target: x86_64-pc-windows-msvc
            os: windows-2019
    runs-on: ${{ matrix.os || 'ubuntu-18.04' }}
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: d_blog #项目名字
          target: ${{ matrix.target }}
          tar: unix
          zip: windows
          token: ${{ secrets.ACTION_ACCESS }}

编写changelog

发布前需要添加对应的更新日志否则会失败,如果没有配置changelog则不填写

模板像这样


# Changelog

All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org).

<!--
Note: In this file, do not use the hard wrap in the middle of a sentence for compatibility with GitHub comment style markdown rendering.
-->

## [Unreleased]

## [0.1.1] - 2024-04-22
- test

## [0.0.5] - 2024-04-19
- bug fix

## [0.0.4] - 2024-04-19
- bug fix

## [0.0.3] - 2024-04-19
- bug fix

提交代码并新建标签

提交代码


git push origin main

新建本地标签


git tag v0.1.1

上传标签,这一步会触发github action 的任务


git push origin v0.1.1

效果预览

过程有点慢,需要耐心等待任务完成 image.png

上传成功后就可以在release里面看到了,整个流程结束

返回顶部