Skip to content

Commit 67d067d

Browse files
committed
chore: add release action
1 parent a1f2baf commit 67d067d

File tree

3 files changed

+128
-5
lines changed

3 files changed

+128
-5
lines changed

.github/workflows/rust.yml renamed to .github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
65
pull_request:
76
branches: [ main ]
8-
workflow_dispatch:
97

108
jobs:
11-
build:
9+
test:
1210
runs-on: ubuntu-latest
1311

1412
steps:

.github/workflows/release.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
jobs:
9+
create-release:
10+
name: create-release
11+
runs-on: ubuntu-22.04
12+
outputs:
13+
upload_url: ${{ steps.release.outputs.upload_url }}
14+
pkg_version: ${{ env.PKG_VERSION }}
15+
steps:
16+
- name: Get the release version from the tag
17+
shell: bash
18+
run: |
19+
echo "PKG_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
20+
echo "version is: ${{ env.PKG_VERSION }}"
21+
- name: Create GitHub release
22+
id: release
23+
uses: actions/create-release@v1
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
tag_name: ${{ env.PKG_VERSION }}
28+
release_name: ${{ env.PKG_VERSION }}
29+
30+
build-release:
31+
name: build-release
32+
needs: ['create-release']
33+
runs-on: ${{ matrix.os }}
34+
env:
35+
CARGO: cargo
36+
TARGET_FLAGS: ""
37+
TARGET_DIR: ./target
38+
strategy:
39+
matrix:
40+
build: [linux, openwrt-arm, macos, macos-arm, win-msvc, win32-msvc]
41+
include:
42+
- build: linux
43+
os: ubuntu-22.04
44+
target: x86_64-unknown-linux-musl
45+
- build: openwrt-arm
46+
os: ubuntu-22.04
47+
target: aarch64-unknown-linux-musl
48+
- build: macos
49+
os: macos-13
50+
target: x86_64-apple-darwin
51+
- build: macos-arm
52+
os: macos-13
53+
target: aarch64-apple-darwin
54+
- build: win-msvc
55+
os: windows-2022
56+
target: x86_64-pc-windows-msvc
57+
- build: win32-msvc
58+
os: windows-2022
59+
target: i686-pc-windows-msvc
60+
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v3
64+
65+
- name: Install Rust
66+
uses: dtolnay/rust-toolchain@master
67+
with:
68+
toolchain: stable
69+
target: ${{ matrix.target }}
70+
71+
- name: Use Cross
72+
shell: bash
73+
run: |
74+
cargo install cross
75+
echo "CARGO=cross" >> $GITHUB_ENV
76+
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
77+
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
78+
79+
- name: Show command used for Cargo
80+
run: |
81+
echo "cargo command is: ${{ env.CARGO }}"
82+
echo "target flag is: ${{ env.TARGET_FLAGS }}"
83+
echo "target dir is: ${{ env.TARGET_DIR }}"
84+
85+
- name: Build release binary
86+
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
87+
88+
- name: Build archive
89+
shell: bash
90+
run: |
91+
pkg_name="script-server"
92+
staging="${pkg_name}-${{ needs.create-release.outputs.pkg_version }}-${{ matrix.target }}"
93+
mkdir -p "$staging"
94+
95+
cp README.md "$staging/"
96+
97+
if [ "${{ matrix.os }}" = "windows-2022" ]; then
98+
cp "target/${{ matrix.target }}/release/${pkg_name}.exe" "$staging/"
99+
7z a "$staging.zip" "$staging"
100+
echo "ASSET=$staging.zip" >> $GITHUB_ENV
101+
else
102+
cp "target/${{ matrix.target }}/release/${pkg_name}" "$staging/"
103+
tar czf "$staging.tar.gz" "$staging"
104+
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
105+
fi
106+
107+
- name: Upload release archive
108+
uses: actions/[email protected]
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
with:
112+
upload_url: ${{ needs.create-release.outputs.upload_url }}
113+
asset_path: ${{ env.ASSET }}
114+
asset_name: ${{ env.ASSET }}
115+
asset_content_type: application/octet-stream

src/utils.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::Result;
2-
use std::{os::unix::prelude::PermissionsExt, path::Path, process::Command};
2+
use std::{path::Path, process::Command};
33
use tiny_http::{Request, Response};
44

55
pub fn has_header(req: &Request, key: &str, value: &str) -> bool {
@@ -12,9 +12,19 @@ pub fn has_header(req: &Request, key: &str, value: &str) -> bool {
1212
false
1313
}
1414

15+
// All files are executable on Windows, so just check is file
16+
#[cfg(windows)]
1517
pub fn executable(file_path: &Path) -> bool {
1618
match file_path.metadata() {
17-
Ok(data) => data.is_file() && data.permissions().mode() & 0o111 != 0,
19+
Ok(data) => data.is_file(),
20+
Err(_) => false,
21+
}
22+
}
23+
#[cfg(unix)]
24+
pub fn executable(file_path: &Path) -> bool {
25+
use std::os::unix::prelude::*;
26+
match file_path.metadata() {
27+
Ok(data) => data.is_file() && data.mode() & 0o111 != 0,
1828
Err(_) => false,
1929
}
2030
}

0 commit comments

Comments
 (0)