Skip to content

Commit

Permalink
Merge branch 'main' into fix-76
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass committed Nov 17, 2023
2 parents 1ac811d + 0ce47bb commit 615cbd4
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 61 deletions.
51 changes: 51 additions & 0 deletions .github/actions/setup_nupm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Setup nupm
description: Install and setup nupm environment

inputs:
nu_version:
required: true
description: "A valid NPM-style semver specification, such as '0.86.0', etc. and 'nightly', supports '0.60.0' -> latest and latest 'nightly'"

nupm_clone_path:
required: true
default: "/tmp/nupm"
description: "The path where nupm will be cloned"

nupm_path:
required: true
default: "~/.local/share/nupm"
description: "The path where nupm will be installed"

outputs:
nupm_path:
value: ${{ steps.set-output.outputs.nupm-path }}
description: "The path to the installed nupm (can be `use`d directly) "

runs:
using: composite
steps:
- uses: hustcer/setup-nu@v3.7
with:
version: ${{ inputs.nu_version }}

- name: Show Nushell Version
run: version
shell: nu {0}

- run: |
git clone --depth 1 https://github.com/nushell/nupm ${{ inputs.nupm_clone_path }}
git -C ${{ inputs.nupm_clone_path }} checkout f7c0843f4d667194beae468614a46cc8d72cc5db
shell: nu {0}
- name: Install nupm
shell: nu {0}
id: set-output
run: |
use ${{ inputs.nupm_clone_path }}/nupm
let nupm_home = "${{ inputs.nupm_path }}" | path expand
with-env {NUPM_HOME: $nupm_home} {
mkdir $env.NUPM_HOME
nupm install --force --path "${{ inputs.nupm_clone_path }}"
}
'nupm-path="${{ inputs.nupm_path }}/modules/nupm"' | save --append $env.GITHUB_OUTPUT
56 changes: 56 additions & 0 deletions .github/actions/sync_action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Sync Action
description: Checks the mergeability of main into nightly and optionally pushes it.

inputs:
do_push:
description: Whether to push changes after syncing
required: true
default: "false"
log_worktree:
description: Whether to log the worktree
required: true
default: "false"

permissions:
contents: write

runs:
using: composite
steps:
- name: Checkout nightly
run: |
git fetch origin main
git fetch origin nightly:nightly
git checkout nightly
shell: bash

- name: Set up Git
shell: bash
run: |
git config user.name "$(git log -n 1 --pretty=format:%an)"
git config user.email "$(git log -n 1 --pretty=format:%ae)"
- name: Show Git config and worktree
shell: bash
run: |
git config --list | grep user.name
git config --list | grep user.email
git log --graph --branches --remotes --tags --oneline --decorate
if: ${{ inputs.log_worktree == 'true' }}

- name: "Attempt to merge main into nightly"
run: |
set +e
git merge --no-ff origin/main -m "Merge main into nightly"
MERGE_STATUS=$?
set -e
if [ $MERGE_STATUS -ne 0 ]; then
echo "Merge conflict detected"
exit 1
fi
shell: bash

- name: "Push to remote"
run: git push origin nightly
shell: bash
if: ${{ inputs.do_push == 'true' && !env.ACT }}
23 changes: 23 additions & 0 deletions .github/workflows/check_nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 🌃 Nightly compatibility check

on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]

jobs:
check-merge:
runs-on: ubuntu-latest
steps:
- name: Checking out repository
uses: actions/checkout@v3
- name: Docker Fix (for act)
run: |
git fetch origin
git reset --hard ${{ github.sha }}
shell: bash
if: ${{ env.ACT }}

- uses: ./.github/actions/sync_action
with:
do_push: false
53 changes: 8 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
name: 🧪 Tests

on:
pull_request:
paths-ignore:
- "**.md"
push:
branches:
- main
workflow_dispatch:

name: continuous-integration

defaults:
run:
shell: nu {0}

env:
NU_LOG_LEVEL: DEBUG
- nightly

jobs:
tests:
strategy:
fail-fast: true
matrix:
platform: [windows-latest, macos-latest, ubuntu-20.04]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v3

- uses: hustcer/setup-nu@v3.6
with:
version: '0.86'

- name: Download the source of Nupm
run: git clone --depth 1 https://github.com/nushell/nupm /tmp/nupm/

- name: Install Nupm
run: |
use /tmp/nupm/nupm
with-env {NUPM_HOME: ("~/.local/share/nupm" | path expand)} {
# FIXME: use --no-confirm option
# related to https://github.com/nushell/nupm/pull/42
mkdir ("~/.local/share/nupm" | path expand)
nupm install --force --path /tmp/nupm
}
- name: Show Nushell Version
run: version

- name: Run the tests
run: |
# FIXME: is there a way to not rely on hardcoded paths here?
use ~/.local/share/nupm/modules/nupm
nupm test --show-stdout
uses: ./.github/workflows/nupm-tests.yml
with:
nu_version: "0.87.0"
54 changes: 54 additions & 0 deletions .github/workflows/nupm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# reusable workflow to be able to provide defaults to the CI
on:
workflow_dispatch:
inputs:
nu_version:
description: "A valid NPM-style semver specification, such as '0.86.0', etc. and 'nightly', supports '0.60.0' -> latest and latest 'nightly'"
default: "*"
type: string
timeout:
description: "The timeout of the ci job. Default is 20min"
default: 20
type: number

workflow_call:
inputs:
nu_version:
description: "A valid NPM-style semver specification, such as '0.86.0', etc. and 'nightly', supports '0.60.0' -> latest and latest 'nightly'"
default: "*"
type: string
timeout:
description: "The timeout of the ci job. Default is 20min"
default: 20
type: number

env:
NU_LOG_LEVEL: DEBUG
GITHUB_TOKEN: ${{ github.token }}

defaults:
run:
shell: nu {0}

jobs:
nupm-tests:
timeout-minutes: ${{ inputs.timeout }}
strategy:
fail-fast: true
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3

- name: Setup nushell and nupm
uses: ./.github/actions/setup_nupm
id: "nu-setup"
with:
nu_version: ${{github.ref == 'refs/heads/nightly' && 'nightly' || inputs.nu_version}}

- name: Run the tests
run: |
use ${{ steps.nu-setup.outputs.nupm_path }}
nupm test --show-stdout
23 changes: 23 additions & 0 deletions .github/workflows/sync_nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 🌃 Sync main to nightly

on:
pull_request:
types: [closed]
branches: [main]

permissions:
contents: write

jobs:
sync_on_merge:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v3
with:
# Fetches all history for all tags and branches
fetch-depth: 0
- uses: ./.github/actions/sync_action
with:
do_push: true
log_worktree: true
6 changes: 2 additions & 4 deletions src/nu-git-manager-sugar/gist.nu
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ export def list [
)}

if ($user | is-empty) {
let span = (metadata $user | get span)
error make {
msg: $"(ansi red)gist::no_user_given(ansi reset)"
label: {
text: "no user given"
start: $span.start
end: $span.end
span: (metadata $user | get span)
}
}
}
Expand Down Expand Up @@ -118,7 +116,7 @@ def "nu-complete list-local-gists" [] {
}

# jump to a gist in the `GIST_HOME`
export def-env goto [
export def --env goto [
gist: string@"nu-complete list-local-gists" # the gist to jump to
] {
cd (gist-home | path join $gist)
Expand Down
10 changes: 3 additions & 7 deletions src/nu-git-manager-sugar/git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export def "lock clean" [] {
}

# go to the root of the repository from anywhere in the worktree
export def-env root [] {
export def --env root [] {
cd (repo-root)
}

Expand Down Expand Up @@ -127,13 +127,11 @@ export def "remote add" [
--ssh # use SSH as the communication protocol
] {
if $name in (remote list | get remote) {
let span = (metadata $name | get span)
error make {
msg: $"(ansi red_bold)remote_already_in_index(ansi reset)"
label: {
text: $"already a remote of ($env.PWD)"
start: $span.start
end: $span.end
span: (metadata $name | get span)
}
}
}
Expand Down Expand Up @@ -186,13 +184,11 @@ export def fixup [
revision: string # the revision of the Git worktree to fixup
] {
if (do --ignore-errors { git rev-parse $revision } | complete | get exit_code) != 0 {
let span = (metadata $revision | get span)
error make {
msg: $"(ansi red_bold)revision_not_found(ansi reset)"
label: {
text: $"($revision) not found in the working tree of ($env.PWD)"
start: $span.start
end: $span.end
span: (metadata $revision | get span)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/nu-git-manager/error/error.nu
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export def throw-error [
msg: $"(ansi red_bold)($error.msg)(ansi reset)"
label: {
text: $error.label.text
start: $error.label.span.start
end: $error.label.span.end
span: $error.label.span
}
}
}
2 changes: 1 addition & 1 deletion src/nu-git-manager/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export def "gm remove" [
$choices | input list $prompt
}

if ($choice | is-empty) {
if $choice == null {
log info "user chose to exit"
return
}
Expand Down
4 changes: 4 additions & 0 deletions tests/gm.nu
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,7 @@ export def store-cleaning [] {
assert not ($env.GIT_REPOS_HOME | path exists)
}
}

export def user-import [] {
^$nu.current-exe --commands "use ./src/nu-git-manager/ *"
}
5 changes: 3 additions & 2 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# > **Important**
# > the `toolkit test` command requires [Nupm](https://github.com/nushell/nupm) to be installed
export def "test" [
pattern?: string = "" # the pattern a test name should match to run
--verbose # show the output of each tests
] {
use nupm

if $verbose {
nupm test --show-stdout
nupm test $pattern --show-stdout
} else {
nupm test
nupm test $pattern
}
}

Expand Down

0 comments on commit 615cbd4

Please sign in to comment.