Skip to content

Commit

Permalink
Merge branch 'main' into skip-confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 authored Nov 6, 2024
2 parents 3930fab + f0734f3 commit ec0dd44
Show file tree
Hide file tree
Showing 35 changed files with 480 additions and 280 deletions.
48 changes: 25 additions & 23 deletions .github/workflows/bashisms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check for bashisms
on:
pull_request:
paths:
- core/tabs/**
- 'core/tabs/**/*.sh'
merge_group:
workflow_dispatch:

Expand All @@ -15,31 +15,33 @@ jobs:
- uses: actions/checkout@v4
- run: git fetch origin ${{ github.base_ref }}

- name: Get a list of changed script files
id: get_sh_files
- name: Install devscripts
run: sudo apt-get update && sudo apt-get install -y devscripts

- name: Get changed .sh files (PR only)
id: changed-sh-files
if: github.event_name == 'pull_request'
uses: tj-actions/changed-files@v45
with:
files: '**/*.sh'

- name: Get all .sh files (if workflow dispatched)
id: sh-files
if: github.event_name != 'pull_request'
run: |
sh_files=$(git diff --name-only origin/${{ github.base_ref }} HEAD core/tabs | grep '\.sh$' || true)
if [ -n "$sh_files" ]; then
echo "$sh_files" > changed_files
echo "changed=1" >> $GITHUB_OUTPUT
files=$(find . -type f -name "*.sh" | tr '\n' ' ')
echo "files=${files:-none}" >> $GITHUB_ENV
- name: Set FILES for bashism check
id: set-files
run: |
if [[ "${{ steps.changed-sh-files.outputs.any_changed }}" == 'true' ]]; then
echo "FILES=${{ steps.changed-sh-files.outputs.all_changed_files }}" >> $GITHUB_ENV
else
echo "changed=0" >> $GITHUB_OUTPUT
echo "FILES=${{ env.files }}" >> $GITHUB_ENV
fi
- name: Install devscripts
if: steps.get_sh_files.outputs.changed == 1
run: sudo apt-get update && sudo apt-get install devscripts
- name: Check for bashisms
if: steps.get_sh_files.outputs.changed == 1
run: |
echo "Running for:\n$(cat changed_files)\n"
for file in $(cat changed_files); do
if [[ -f "$file" ]]; then
checkbashisms "$file"
fi
done
- name: Remove the created file
if: steps.get_sh_files.outputs.changed == 1
run: rm changed_files
IFS=' ' read -r -a file_array <<< "$FILES"
checkbashisms "${file_array[@]}"
18 changes: 14 additions & 4 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: linutil_env
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout Repository
Expand All @@ -24,11 +28,17 @@ jobs:
run: |
echo -e "<!-- THIS FILE IS GENERATED AUTOMATICALLY. EDIT .github/CONTRIBUTING.md -->\n\n$(cat .github/CONTRIBUTING.md)" > 'docs/contributing.md'
- uses: stefanzweifel/git-auto-commit-action@v5
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit_message: Commit Contributing Guidelines
file_pattern: "docs/contributing.md"
add_options: '--force'
commit-message: Update Contributing Guidelines
title: 'docs: Update Contributing Guidelines'
body: 'Automated update of Contributing Guidelines from .github/CONTRIBUTING.md'
branch: update-contributing-guidelines
delete-branch: true
base: main
labels: documentation
token: ${{ secrets.PAT_TOKEN }}
if: success()

- name: Setup Python
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/linutil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,3 @@ jobs:
env:
version: ${{ env.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: linutil-artifact
path: build/x86_64-unknown-linux-musl/release/linutil
compression-level: 0
overwrite: true
67 changes: 45 additions & 22 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: LinUtil Preview
on:
workflow_dispatch:
inputs:
run_id:
description: 'Run ID of LinUtil Release'
tag_name:
description: 'Tag name'
required: true
workflow_run:
workflows: ["LinUtil Release"]
Expand All @@ -14,29 +14,47 @@ on:
jobs:
generate_preview:
runs-on: ubuntu-latest
environment: linutil_env
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- name: Checkout source
uses: actions/checkout@v4

- name: Set Run ID
run: |
if [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "run_id=${{ github.event.workflow_run.id }}" >> $GITHUB_ENV
else
echo "run_id=${{ github.event.inputs.run_id }}" >> $GITHUB_ENV
fi
- name: Download build artifacts
uses: actions/download-artifact@v4
- name: Get tag name ( Workflow Run )
id: latest_tag
uses: actions/github-script@v7
if: github.event_name == 'workflow_run'
with:
name: linutil-artifact
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ env.run_id }}
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1
});
core.setOutput('result', releases.data[0].tag_name);
result-encoding: string

- name: Set tag name ( Workflow Run )
if: github.event_name == 'workflow_run'
run: echo "tag_name=${{ steps.latest_tag.outputs.result }}" >> $GITHUB_ENV

- name: Set tag name ( Workflow Dispatch )
if: ${{ github.event_name }} == 'workflow_dispatch'
run: echo "tag_name=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV

- name: Download binary
run: |
curl -LO "https://github.com/${{ github.repository }}/releases/download/${{ env.tag_name }}/linutil"
- name: Set env
run: |
chmod +x linutil
echo "${{ github.workspace }}" >> $GITHUB_PATH
mkdir -p build
mv linutil build/linutil
echo "${{ github.workspace }}/build" >> $GITHUB_PATH
- name: Generate preview
uses: charmbracelet/[email protected]
Expand All @@ -46,10 +64,15 @@ jobs:
- name: Move preview
run: mv preview.gif docs/assets/preview.gif

- name: Upload preview
uses: stefanzweifel/git-auto-commit-action@v5
- name: Create PR
uses: peter-evans/[email protected]
with:
commit_message: Preview for ${{ env.run_id }}
file_pattern: "docs/assets/preview.gif"
add_options: "--force"
commit-message: Preview for ${{ env.tag_name }}
file-pattern: "docs/assets/preview.gif"
add-options: "--force"
token: ${{ secrets.PAT_TOKEN }}
branch: feature/preview-${{ env.tag_name }}
title: "Update preview for ${{ env.tag_name }}"
body: |
Automated PR to update preview gif for version ${{ env.tag_name }}
if: success()
1 change: 1 addition & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- name: Run ShellCheck
uses: reviewdog/action-shellcheck@v1
with:
shellcheck_flags: '--source-path=${{ github.workspace }}/.shellcheckrc'
reviewdog_flags: '-fail-level=any'

shfmt:
Expand Down
2 changes: 2 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
external-sources=true
source=core/tabs/common-script.sh
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 25 additions & 31 deletions core/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,18 @@ pub fn get_tabs(validate: bool) -> (TempDir, Vec<Tab>) {

let tabs: Vec<Tab> = tabs
.into_iter()
.map(
|(
TabEntry {
name,
data,
multi_selectable,
},
directory,
)| {
let mut tree = Tree::new(Rc::new(ListNode {
name: "root".to_string(),
description: String::new(),
command: Command::None,
task_list: String::new(),
}));
let mut root = tree.root_mut();
create_directory(data, &mut root, &directory, validate);
Tab {
name,
tree,
multi_selectable,
}
},
)
.map(|(TabEntry { name, data }, directory)| {
let mut tree = Tree::new(Rc::new(ListNode {
name: "root".to_string(),
description: String::new(),
command: Command::None,
task_list: String::new(),
multi_select: false,
}));
let mut root = tree.root_mut();
create_directory(data, &mut root, &directory, validate, true);
Tab { name, tree }
})
.collect();

if tabs.is_empty() {
Expand All @@ -74,12 +62,6 @@ struct TabList {
struct TabEntry {
name: String,
data: Vec<Entry>,
#[serde(default = "default_multi_selectable")]
multi_selectable: bool,
}

fn default_multi_selectable() -> bool {
true
}

#[derive(Deserialize)]
Expand All @@ -94,6 +76,12 @@ struct Entry {
entry_type: EntryType,
#[serde(default)]
task_list: String,
#[serde(default = "default_true")]
multi_select: bool,
}

fn default_true() -> bool {
true
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -174,24 +162,29 @@ fn create_directory(
node: &mut NodeMut<Rc<ListNode>>,
command_dir: &Path,
validate: bool,
parent_multi_select: bool,
) {
for entry in data {
let multi_select = parent_multi_select && entry.multi_select;

match entry.entry_type {
EntryType::Entries(entries) => {
let mut node = node.append(Rc::new(ListNode {
name: entry.name,
description: entry.description,
command: Command::None,
task_list: String::new(),
multi_select,
}));
create_directory(entries, &mut node, command_dir, validate);
create_directory(entries, &mut node, command_dir, validate, multi_select);
}
EntryType::Command(command) => {
node.append(Rc::new(ListNode {
name: entry.name,
description: entry.description,
command: Command::Raw(command),
task_list: String::new(),
multi_select,
}));
}
EntryType::Script(script) => {
Expand All @@ -210,6 +203,7 @@ fn create_directory(
file: script,
},
task_list: entry.task_list,
multi_select,
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub enum Command {
pub struct Tab {
pub name: String,
pub tree: Tree<Rc<ListNode>>,
pub multi_selectable: bool,
}

#[derive(Clone, Hash, Eq, PartialEq)]
Expand All @@ -32,4 +31,5 @@ pub struct ListNode {
pub description: String,
pub command: Command,
pub task_list: String,
pub multi_select: bool,
}
Loading

0 comments on commit ec0dd44

Please sign in to comment.