Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add sha256sum and version.txt #599

Merged
merged 10 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 57 additions & 45 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,48 @@ 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
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 +331,18 @@ 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
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
Expand All @@ -353,13 +364,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 +381,21 @@ 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
Itsusinn marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ steps.get-info.outputs.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");
ibigbug marked this conversation as resolved.
Show resolved Hide resolved
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}");
}
18 changes: 16 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,27 @@ 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!("CLASH_VERSION_OVERRIDE"));
Itsusinn marked this conversation as resolved.
Show resolved Hide resolved
exit(0)
}

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