Skip to content

Commit

Permalink
ci: add sha256sum and version.txt (#599)
Browse files Browse the repository at this point in the history
* ci: add sha256sum and version.txt

* ci: improve git tag

* build: change alpha release version format

* ci(docker): build docker images when nightly relase, but not push it

* ci: change nightly version format

* ci: add RISC-V

* ci: remove RISC-V

* refactor: add package name to cli -v

* fix
  • Loading branch information
Itsusinn authored Sep 19, 2024
1 parent 96374d6 commit e8345a3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 49 deletions.
106 changes: 59 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches: [ "master" ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha || github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
Expand All @@ -32,15 +32,15 @@ jobs:
# when not set, default will be used (except target, cross)
# - os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# release-name: x86_64-linux
# toolchain: stable
# cross: true
# release-name: $target
# toolchain: nightly
# cross: false
# postfix: ""
# extra-args: ""
# components: ""
# rustflags: ""
# rustflags: "--cfg tokio_unstable"

# Linux x86
# Linux x86 gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
cross: true
Expand All @@ -49,26 +49,25 @@ jobs:
target: i686-unknown-linux-gnu
cross: true
extra-args: "--all-features"
# Linux x86 static-crt
# Linux x86 musl
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
release-name: x86_64-unknown-linux-gnu-static-crt
target: x86_64-unknown-linux-musl
cross: true
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
# Linux x86_64-unknown-linux-musl
# Linux x86 gnu static-crt
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
release-name: x86_64-unknown-linux-musl
target: x86_64-unknown-linux-gnu
release-name: x86_64-unknown-linux-gnu-static-crt
cross: true
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
- os: ubuntu-latest
target: i686-unknown-linux-gnu
release-name: i686-unknown-linux-gnu-static-crt
cross: true
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
# Linux arm
# Linux arm gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
cross: true
Expand All @@ -81,29 +80,33 @@ jobs:
target: armv7-unknown-linux-gnueabihf
cross: true
extra-args: "--all-features"
# Linux arm static-crt
# Linux arm musl
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
release-name: aarch64-unknown-linux-gnu-static-crt
target: aarch64-unknown-linux-musl
cross: true
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
release-name: aarch64-unknown-linux-musl
target: armv7-unknown-linux-musleabihf
cross: true
extra-args: "--all-features"
# Linux arm gnu static-crt
- os: ubuntu-latest
target: armv7-unknown-linux-gnueabi
release-name: armv7-unknown-linux-gnueabi-static-crt
target: aarch64-unknown-linux-gnu
release-name: aarch64-unknown-linux-gnu-static-crt
cross: true
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
target: armv7-unknown-linux-gnueabi
release-name: armv7-unknown-linux-gnueabi-static-crt
cross: true
extra-args: "--all-features"
rustflags: "--cfg tokio_unstable"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
# Linux RISC-V gnu
# - os: ubuntu-latest
# target: riscv64gc-unknown-linux-gnu
# cross: true
# extra-args: "--all-features"
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
Expand Down Expand Up @@ -165,7 +168,6 @@ jobs:
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
# Linux mips: tier-3, pity
# Linux risc-v: needs update rustls
# Windows gnu: tokio dont work
# Windows aarch: todo

Expand Down Expand Up @@ -258,7 +260,6 @@ jobs:

release:
name: Release
if: github.event_name != 'pull_request'
needs: [ compile ]
runs-on: ubuntu-latest
steps:
Expand All @@ -280,37 +281,49 @@ jobs:
name: binaries
path: ./packages

- name: Delete previous latest tag
- name: Clean git tag & release
if: startsWith(github.ref, 'refs/heads/master')
run: |
# Deleted latest tag and push it
git tag -d latest || true
git push origin :refs/tags/latest || true
# Deleted all drafts
gh release list | grep Draft | awk '{print $1 " \t"}' | while read -r line; do gh release delete -y "$line"; done
env:
GH_TOKEN: ${{ github.token }}

- name: Create new latest tag
if: startsWith(github.ref, 'refs/heads/master')
- name: Clean git tag
if: startsWith(github.ref, 'refs/tags/v*')
run: |
git tag latest
git push origin latest
# Delete latest tag (for git-cliff)
git tag -d latest || true
- name: Create SHA256Sums.txt and version.txt
run: |
cd packages
sha256sum * >> sha256sums.txt
cat sha256sums.txt
chmod +x ./clash-x86_64-unknown-linux-musl
./clash-x86_64-unknown-linux-musl -v >> version.txt
cat version.txt
- name: Generate a changelog
uses: orhun/git-cliff-action@main
id: git-cliff
with:
config: .github/cliff.toml
args: --latest --strip header
args: --latest --strip header
env:
GITHUB_REPO: ${{ github.repository }}

- name: Github stable release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
token: "${{ secrets.GITHUB_TOKEN }}"
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
generate_release_notes: false
body: "${{ steps.git-cliff.outputs.content }}"
body: ${{ steps.git-cliff.outputs.content }}
files: |
packages/*
LICENSE*
Expand All @@ -319,19 +332,19 @@ jobs:
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/heads/master')
with:
token: "${{ secrets.GITHUB_TOKEN }}"
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: "latest"
generate_release_notes: false
body: "${{ steps.git-cliff.outputs.content }}"
body: ${{ steps.git-cliff.outputs.content }}
files: |
packages/*
LICENSE*
docker-image:
needs: [ compile ]
name: Docker Image
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
Expand All @@ -341,9 +354,8 @@ jobs:
submodules: true

- name: Get the current Git commit hash
id: get-info
run: |
echo "OWNER=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_OUTPUT
echo "OWNER=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_ENV
echo "TAG_VERSION=${REGISTRY}/${GITHUB_REPOSITORY_OWNER@L}/${IMAGE_NAME}:${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TAG_LATEST=${REGISTRY}/${GITHUB_REPOSITORY_OWNER@L}/${IMAGE_NAME}:latest" >> $GITHUB_ENV
Expand All @@ -353,13 +365,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ steps.get-info.outputs.OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download binaries amd64
uses: actions/download-artifact@v4
with:
Expand All @@ -377,13 +382,20 @@ jobs:
mv ./clash-rs/clash-x86_64-unknown-linux-musl ./clash-rs/clash-amd64
mv ./clash-rs/clash-aarch64-unknown-linux-musl ./clash-rs/clash-arm64
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push release
uses: docker/build-push-action@v6
with:
context: .
file: .github/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
tags: ${{ env.TAG_VERSION }},${{ env.TAG_LATEST }}


Expand Down
14 changes: 14 additions & 0 deletions clash/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(let_chains)]
fn main() {
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
let version = if let Some("refs/heads/master") = option_env!("GITHUB_REF")
&& let Some(sha) = option_env!("GITHUB_SHA")
{
let short_sha = &sha[..7];
// Nightly relase below
format!("{}-alpha+sha.{short_sha}", env!("CARGO_PKG_VERSION"))
} else {
env!("CARGO_PKG_VERSION").into()
};
println!("cargo:rustc-env=CLASH_VERSION_OVERRIDE={version}");
}
22 changes: 20 additions & 2 deletions clash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(author, about, long_about = None)]
struct Cli {
#[clap(short, long, value_parser, value_name = "DIRECTORY")]
directory: Option<PathBuf>,
Expand All @@ -31,13 +31,31 @@ struct Cli {
help = "Test configuration and exit"
)]
test_config: bool,

#[clap(
short,
long,
visible_short_aliases = ['V'],
value_parser,
default_value = "false",
help = "Print clash-rs version and exit"
)]
version: bool,
#[clap(short, long, help = "Additinally log to file")]
log_file: Option<String>,
}

fn main() {
let cli = Cli::parse();

if cli.version {
println!(
"{} {}",
env!("CARGO_PKG_NAME"),
env!("CLASH_VERSION_OVERRIDE")
);
exit(0)
}

let file = cli
.directory
.as_ref()
Expand Down

0 comments on commit e8345a3

Please sign in to comment.