Skip to content

Commit

Permalink
Add github actions (#1)
Browse files Browse the repository at this point in the history
* Add github actions

* Add missing actions references

* Remove use of unmaintained action

* Fix matrix strategy and added dependencies for `aarch64-unknown-linux-gnu` compilation

* Add caching, calls to rustfmt, and improved descriptions

* Fix lint errors

* Add release action

* Change releasae action triggers for testing

* Modify path

* Fix file path

* Fix file path

* Fix file path

* Add ceation of release

* Add missing checkout action

* Fix permissions

* Remove upload of binaries

* Fix typo

* Add upload of binaries to release

* Fix upload binary path

* Fix download of artifacts

* Add debug steps

* Fix binary path

* Rename artifact before uploading asset to release

* Add retention rules to upload and remove windows upload for testing

* Fix download path

* Add prerelease to releases and change trigger

* Implement reusable workflows to reduce code duplication
  • Loading branch information
dloez committed Jul 9, 2023
1 parent 9812ce6 commit 9bc19e6
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
Empty file added .github/release_notes.template
Empty file.
69 changes: 69 additions & 0 deletions .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build and lint
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_call:
inputs:
for_release:
type: boolean
description: |
Mark if additional steps required for a release, like uploading artifacts, should be executed
required: true
default: false
version:
type: string
description: Project version used for naming artifacts
required: true
jobs:
build:
strategy:
matrix:
os-target:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
runs-on: ${{ matrix.os-target.os }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.70.0
targets: ${{ matrix.os-target.target }}
- uses: Swatinem/rust-cache@v2
- name: Install aarch64-unknown-linux-gnu requisites
run: sudo apt-get install g++-aarch64-linux-gnu -y
if: matrix.os-target.target == 'aarch64-unknown-linux-gnu'
- name: Run cargo check
run: cargo build --release --target ${{ matrix.os-target.target }}
- name: Upload artifacts for reuse in release job
uses: actions/upload-artifact@v3
if: ${{ inputs.for_release }}
with:
name: arcanist_${{ inputs.version }}_${{ matrix.os-target.target }}
path: ${{ github.workspace }}/target/${{ matrix.os-target.target }}/release/arcanist${{ matrix.os-target.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
if-no-files-found: error
retention-days: 5
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.70.0
components: clippy,rustfmt
- uses: Swatinem/rust-cache@v2
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Run rustfmt
run: cargo fmt --all -- --check
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Create release
on:
push:
tags:
- "v*.*.*"
jobs:
setup-validation:
outputs:
version: ${{ steps.gather-version.outputs.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract version from Cargo.toml
id: gather-version
run: echo version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "arcanist").version') >> $GITHUB_OUTPUT
- name: Ensure release does not already exist
run: |
git fetch origin &> /dev/null
version=${{ steps.gather-version.outputs.version }}
if [[ -n "$(git tag -l v${version})" ]]; then
echo "A release '${version}' already exists." >&2
exit 1
else
echo "Tag 'v${version}' will be created"
fi
build-lint:
uses: ./.github/workflows/build_lint.yml
needs: setup-validation
with:
for_release: true
version: ${{ needs.setup-validation.outputs.version }}
release:
needs: [setup-validation, build-lint]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Generate release notes
run: |
sed 's/{version}/${{ needs.setup-validation.outputs.version }}/g' ${{ github.workspace }}/.github/release_notes.template \
> ${{ github.workspace }}/.github/release_notes.txt
- name: Create release
uses: softprops/action-gh-release@v1
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
generate_release_notes: true
name: Arcanist - ${{ needs.setup-validation.outputs.version }}
tag_name: v${{ needs.setup-validation.outputs.version }}
body_path: ${{ github.workspace }}/.github/release_notes.txt
target_commitish: ${{ github.base_ref }}
prerelease: true
upload-to-release:
needs: [setup-validation, build-lint, release]
permissions:
contents: write
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: arcanist_${{ needs.setup-validation.outputs.version }}_${{ matrix.target }}
path: ${{ github.workspace }}/target/${{ matrix.target }}/release
- name: Upload arcanist binary to release
run: |
mv ${{ github.workspace }}/target/${{ matrix.target }}/release/arcanist${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }} \
arcanist_${{ needs.setup-validation.outputs.version }}_${{ matrix.target }}${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
gh release upload v${{ needs.setup-validation.outputs.version }} \
arcanist_${{ needs.setup-validation.outputs.version }}_${{ matrix.target }}${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

mod python;
mod yaml;
Expand All @@ -14,19 +14,19 @@ pub enum WrapperKind {
}

trait WrapperKindActions {
fn does_function_exists(&self, spec_file_path: &PathBuf, function_name: &str) -> bool;
fn call_function(&self, spec_file_path: &PathBuf, function_name: &str);
fn does_function_exists(&self, spec_file_path: &Path, function_name: &str) -> bool;
fn call_function(&self, spec_file_path: &Path, function_name: &str);
}

impl WrapperKindActions for WrapperKind {
fn does_function_exists(&self, spec_file_path: &PathBuf, function_name: &str) -> bool {
fn does_function_exists(&self, spec_file_path: &Path, function_name: &str) -> bool {
match self {
WrapperKind::Yaml => todo!(),
WrapperKind::Python => python::does_function_exists(spec_file_path, function_name),
}
}

fn call_function(&self, spec_file_path: &PathBuf, function_name: &str) {
fn call_function(&self, spec_file_path: &Path, function_name: &str) {
match self {
WrapperKind::Yaml => todo!(),
WrapperKind::Python => python::call_function(spec_file_path, function_name),
Expand Down
12 changes: 6 additions & 6 deletions src/wrapper/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use duct::cmd;
use std::fs;
use std::io::BufRead;
use std::io::BufReader;
use std::path::PathBuf;
use std::path::Path;

use regex::Regex;

const REGEX_FUNCTION_PATTERN: &str = r"def[ \t]*{{function_name}}\b.*:";

pub fn does_function_exists(spec_file_path: &PathBuf, function_name: &str) -> bool {
let file_content =
fs::read_to_string(spec_file_path).expect(&format!("Failed to read {:?}", spec_file_path));
pub fn does_function_exists(spec_file_path: &Path, function_name: &str) -> bool {
let file_content = fs::read_to_string(spec_file_path)
.unwrap_or_else(|_| panic!("Failed to read {:?}", spec_file_path));

let regex_pattern = &REGEX_FUNCTION_PATTERN.replace("{{function_name}}", function_name);
let regex = Regex::new(&regex_pattern).expect("Failed to define regex");
let regex = Regex::new(regex_pattern).expect("Failed to define regex");
regex.is_match(&file_content)
}

pub fn call_function(spec_file_path: &PathBuf, function_name: &str) {
pub fn call_function(spec_file_path: &Path, function_name: &str) {
let python_code = "\
import importlib.util; \
spec = importlib.util.spec_from_file_location('main', '{{spec_file_path}}'); \
Expand Down

0 comments on commit 9bc19e6

Please sign in to comment.