Skip to content

Commit

Permalink
Merge pull request #106 from dzcode-io/chore/draf-release-via-github-…
Browse files Browse the repository at this point in the history
…action

chore: draft release via GitHub action
  • Loading branch information
ZibanPirate authored Nov 21, 2024
2 parents 90d256e + e3f5aea commit e3f98c1
Show file tree
Hide file tree
Showing 12 changed files with 2,032 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ rust:

c:
- changed-files:
- any-glob-to-any-file: "c/**"
- any-glob-to-any-file: "c/**"

d:
- changed-files:
- any-glob-to-any-file: "d/**"
- any-glob-to-any-file: "d/**"
4 changes: 2 additions & 2 deletions .github/workflows/c-gen-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
- name: Build docs with Doxygen
uses: mattnotmitt/doxygen-action@v1.9.5
with:
working-directory: 'c/'
doxyfile-path: 'Doxyfile'
working-directory: "c/"
doxyfile-path: "Doxyfile"

- name: Publish to GitHub Pages
if: success()
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/c-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag (.eg v1.0.0)'
description: "Release tag (.eg v1.0.0)"
required: true
type: string

Expand Down Expand Up @@ -51,15 +51,15 @@ jobs:
- name: Create archive
uses: TheDoctor0/zip-release@0.7.6
with:
type: 'tar'
filename: 'github-release/c-release.tar.gz'
directory: 'c'
exclusions: './build/* github-release'
type: "tar"
filename: "github-release/c-release.tar.gz"
directory: "c"
exclusions: "./build/* github-release"

- name: Upload release
uses: ncipollo/release-action@v1.14.0
with:
name: 'Kuliya latest'
artifacts: 'c/github-release/c-release.tar.gz'
tag: 'c-${{ inputs.tag }}'
name: "Kuliya latest"
artifacts: "c/github-release/c-release.tar.gz"
tag: "c-${{ inputs.tag }}"
token: ${{ secrets.GITHUB_TOKEN }}
142 changes: 71 additions & 71 deletions .github/workflows/draft-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,77 @@ name: "Draft New Release"
run-name: "Draft: ${{ github.event.inputs.project }}-${{ github.event.inputs.version }}"

on:
workflow_dispatch:
inputs:
project:
type: choice
options:
- "c"
- "csharp"
- "d"
- "java"
- "javascript"
- "php"
- "python"
- "rust"
required: true
version:
description: "eg. 0.1.0"
required: true
workflow_dispatch:
inputs:
project:
type: choice
options:
- "c"
- "csharp"
- "d"
- "java"
- "javascript"
- "php"
- "python"
- "rust"
required: true
version:
description: "eg. 0.1.0"
required: true

jobs:
apply-version-rust:
name: "Apply Version for: ${{ github.event.inputs.project }}"
runs-on: ubuntu-latest
if: ${{ github.event.inputs.project == 'rust' }}
env:
CWD: "./${{ github.event.inputs.project }}"
PROJECT: ${{ github.event.inputs.project }}
PUBLISH_VERSION: ${{ github.event.inputs.version }}
BRANCH: "main"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo install cargo-bump
working-directory: ${{ env.CWD }}
- run: cargo bump ${{ env.PUBLISH_VERSION }}
working-directory: ${{ env.CWD }}
- run: cargo build
working-directory: ${{ env.CWD }}
- name: "Commit and Push"
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git checkout ${{ env.BRANCH }}
git add .
git commit -m "$PROJECT$PUBLISH_VERSION"
git push origin HEAD:refs/heads/${{ env.BRANCH }}
apply-version-rust:
name: "Apply Version for: ${{ github.event.inputs.project }}"
runs-on: ubuntu-latest
if: ${{ github.event.inputs.project == 'rust' }}
env:
CWD: "./${{ github.event.inputs.project }}"
PROJECT: ${{ github.event.inputs.project }}
PUBLISH_VERSION: ${{ github.event.inputs.version }}
BRANCH: "main"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo install cargo-bump
working-directory: ${{ env.CWD }}
- run: cargo bump ${{ env.PUBLISH_VERSION }}
working-directory: ${{ env.CWD }}
- run: cargo build
working-directory: ${{ env.CWD }}
- name: "Commit and Push"
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git checkout ${{ env.BRANCH }}
git add .
git commit -m "$PROJECT$PUBLISH_VERSION"
git push origin HEAD:refs/heads/${{ env.BRANCH }}
draft-github-release:
name: "Draft GitHub Release"
runs-on: ubuntu-latest
needs: [apply-version-rust]
permissions:
contents: write
env:
PROJECT: ${{ github.event.inputs.project }}
PUBLISH_VERSION: ${{ github.event.inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: "main"
steps:
- name: "Create Release"
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ env.PROJECT }}-${{ env.PUBLISH_VERSION }}",
"target_commitish": "${{ env.BRANCH }}",
"name": "${{ env.PROJECT }}-${{ env.PUBLISH_VERSION }}",
"body": "",
"draft": true,
"prerelease": false
}' \
https://api.github.com/repos/${{ github.repository }}/releases
draft-github-release:
name: "Draft GitHub Release"
runs-on: ubuntu-latest
needs: [apply-version-rust]
permissions:
contents: write
env:
PROJECT: ${{ github.event.inputs.project }}
PUBLISH_VERSION: ${{ github.event.inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: "main"
steps:
- name: "Create Release"
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ env.PROJECT }}-${{ env.PUBLISH_VERSION }}",
"target_commitish": "${{ env.BRANCH }}",
"name": "${{ env.PROJECT }}-${{ env.PUBLISH_VERSION }}",
"body": "",
"draft": true,
"prerelease": false
}' \
https://api.github.com/repos/${{ github.repository }}/releases
39 changes: 24 additions & 15 deletions .github/workflows/rust-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@ jobs:
build_and_test:
name: kuliya - latest
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
env:
CWD: "rust"
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }}
- run: rustup default ${{ matrix.toolchain }}
- run: rustup component add clippy
- run: cd rust && cargo clippy --all-features -- -Dwarnings
- run: cd rust && cargo build --verbose
- run: cd rust && cargo test --verbose
- run: cd rust && cargo test --verbose --lib --bins --tests --features serde_derive
- run: cd rust && cargo test --verbose --lib --bins --tests --no-default-features --features storage
- run: cd rust && cargo test --verbose --all-features
with:
fetch-depth: 0
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy
- run: cargo install cargo-readme
- run: cargo readme > README.md
working-directory: ${{ env.CWD }}
- run: cargo clippy --all-features -- -Dwarnings
working-directory: ${{ env.CWD }}
- run: cargo build --verbose
working-directory: ${{ env.CWD }}
- name: "is docs updated and generated files are committed"
run: exit $(git status --porcelain | wc -l)
- run: cargo test --verbose
working-directory: ${{ env.CWD }}
- run: cargo test --verbose --lib --bins --tests --features serde_derive
working-directory: ${{ env.CWD }}
- run: cargo test --verbose --lib --bins --tests --no-default-features --features storage
working-directory: ${{ env.CWD }}
- run: cargo test --verbose --all-features
working-directory: ${{ env.CWD }}
22 changes: 22 additions & 0 deletions .github/workflows/rust-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "CD"
run-name: "Publish: ${{ github.ref_name }}"

on:
push:
tags:
- "rust-*"

jobs:
publish:
name: cargo publish
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
CWD: "rust"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo publish
working-directory: ${{ env.CWD }}
2 changes: 1 addition & 1 deletion rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target
src/static/_auto_generated

2 changes: 2 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[package]
name = "kuliya"
description = "A library for querying Algerian education dataset."
version = "0.1.0"
edition = "2021"
license = "MIT"

[package.metadata.docs.rs]
all-features = true
Expand Down
25 changes: 18 additions & 7 deletions rust/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# kuliya for Rust
# kuliya

Algeria's college hierarchy dataset as Cargo package
Algeria's college hierarchy dataset as a crate with useful APIs.

# Get started
Example

WIP
```rust
use kuliya::r#static::api::get_node_by_path;

# Contribute
let faculty_of_science_and_technology = get_node_by_path("umkb/fst");

Please install Rust compiler using https://rustup.rs/
assert_eq!(faculty_of_science_and_technology.is_some(), true);

Feel free to ask for help in [#kuliya](https://dzcode.slack.com/archives/C01C0155CKC) group chat
let faculty_of_science_and_technology = faculty_of_science_and_technology.unwrap();

assert_eq!(faculty_of_science_and_technology.name.ar, "كلية العلوم والتكنلوجيا");

// when the path is not found, the function returns None
let non_existing_node = get_node_by_path("umkb/fst/unknown");

assert_eq!(non_existing_node.is_none(), true);
```

License: MIT
32 changes: 20 additions & 12 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,26 @@ mod r#static {
};

let sub_dirs = fs::read_dir(&dir).unwrap();
let children = sub_dirs.filter_map(|entry| {
let entry = entry.unwrap();
let ty = entry.file_type().unwrap();
if ty.is_dir() {
Some(dir_tree_to_list(entry.path()))
} else {
None
}
});
let mut children: Vec<(String, String)> = sub_dirs
.filter_map(|entry| {
let entry = entry.unwrap();
let ty = entry.file_type().unwrap();
if ty.is_dir() {
Some(dir_tree_to_list(entry.path()))
} else {
None
}
})
.collect();
// to ensure deterministic output on different platforms
children.sort();

let mut constants = String::new();
let mut matches = String::new();
children.for_each(|(c, m)| {
for (c, m) in children {
constants.push_str(&c);
matches.push_str(&m);
});
}

(
format!("{}{}", this_node, constants),
Expand Down Expand Up @@ -134,7 +138,11 @@ pub mod data;
}

pub fn main() {
generate_data_file().unwrap();
if Path::new("../_data").exists() {
generate_data_file().unwrap();
} else {
println!("No _data directory found. Skipping data generation.");
}
}
}

Expand Down
Loading

0 comments on commit e3f98c1

Please sign in to comment.