Skip to content

Commit

Permalink
BREAKING_CHANGES: installing nim without choosenim 🔥 #483 (#491)
Browse files Browse the repository at this point in the history
* fix: mac slow install

* feat: composite action

* fix: no

* add env

* Revert "fix: no"

This reverts commit bbe060a.

* add: script

* fix path

* latest install

* stable install

* WIP: testcase

* windows

* windows test

* fix PATH

* debug

* quite

* fix if

* debug

* pwsh

* mkdir

* add comment

* fix description

* add macos test

* uname

* fix arch

* fix mac os

* fix os

* fix

* build for mac

* comment out

* fix repo token

* fix auth

* sh

* debug

* fix build

* del: ls

* change build options

* add macos-latest test

* add info log

* del: unused inputs

* feat: 1.x pattern

* add tests

* add: print version

* del: too old version

* Revert "del: unused inputs"

This reverts commit 45b4264.

* fix: change message

* del: unused ci tests

* docs: update setup-nim-action version to v2-beta

* fix: install_nim.sh path

* feat: build devel nim compiler

* ci: add devel test

* fix: description of nim-install-directory parameter

* docs: v2-beta to v2

* docs: migration to v2 from v1

* docs: v2 section

* docs: fix link

* docs: add issues link

* docs: change cache key

* docs: update devel usage

* docs: remove choosenim cache

* docs: add QA section
  • Loading branch information
jiro4989 authored Jul 6, 2024
1 parent 6cfd17c commit 2910000
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 61 deletions.
34 changes: 10 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,19 @@ on:
- '*.md'

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run test
run: npm test
- name: Check unused packages
run: npm run check-deps

test-actions-on-cross-platform:
test-on-cross-platform:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macOS-13
- macOS-latest
version:
- 1.4.0
- stable
- 2.0.x
- devel
exclude:
- os: macOS-latest
version: 1.4.0
- os: macOS-latest
version: devel
- os: windows-latest
version: 1.4.0
- os: windows-latest
version: devel
steps:
Expand All @@ -62,16 +44,20 @@ jobs:
- name: Run command
run: nimjson -h

test-actions:
runs-on: ubuntu-latest
test-multi-versions:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
version:
- 1.4.x
- 1.6.0
- 1.6.x
- 1.x
- 2.0.x
- 2.x
- '#version-1-6'
- stable
steps:
- uses: actions/checkout@v4
- uses: ./
Expand Down
146 changes: 116 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,116 @@ This action sets up a [Nim-lang](https://nim-lang.org/):crown: environment.

<!-- vim-markdown-toc GFM -->

* [Usage](#mag_rightusage)
* [`v2` version was released :tada:](#v2-version-was-released-tada)
* [Migration to v2 from v1](#migration-to-v2-from-v1)
* [Q&A](#qa)
* [getAppFilename failed](#getappfilename-failed)
* [:mag_right:Usage](#mag_rightusage)
* [Basic usage](#basic-usage)
* [Setup a latest patch version Nim](#setup-a-latest-patch-version-nim)
* [Setup a latest minor version Nim](#setup-a-latest-minor-version-nim)
* [Cache usage](#cache-usage)
* [Matrix testing usage](#matrix-testing-usage)
* [`devel` usage](#devel-usage)
* [Full example](#full-example)
* [Development](#hammerdevelopment)
* [License](#page_facing_uplicense)
* [:hammer:Development](#hammerdevelopment)
* [:page_facing_up:License](#page_facing_uplicense)

<!-- vim-markdown-toc -->

## `v2` version was released :tada:

setup-nim-action has released `v2` ( <https://github.com/jiro4989/setup-nim-action/pull/491> ).

setup-nim-action `v1` depended on `choosenim`.
One day, an issue occurred that installation became very slow with `choosenim` ( <https://github.com/jiro4989/setup-nim-action/issues/483> ).
This process took between 6 and 20 minutes.

I changed setup-nim-action so that is does not use choosenim to solve this problem.

## Migration to v2 from v1

1. Upgrade version of setup-nim-action to `v2` from `v1`
1. Change cache key to clear cache if you are using it.
The key can be anything if the cache will be cleared.
Nothing to do if you are not using `actions/cache`
1. Remove caching `choosenim` if you are using it.
setup-nim-action does not use choosenim now.
Nothing to do if you are not these parameters
1. Remove `yes` and `no-color` parameters if you are using it.
These parameters are not used now.
Nothing to do if you are not these parameters

```diff
steps:
- uses: actions/checkout@v3

- name: Cache nimble
id: cache-nimble
uses: actions/cache@v3
with:
path: ~/.nimble
- key: ${{ runner.os }}-nimble-${{ hashFiles('*.nimble') }}
+ key: ${{ runner.os }}-nimble-v2-${{ hashFiles('*.nimble') }}
restore-keys: |
- ${{ runner.os }}-nimble-
+ ${{ runner.os }}-nimble-v2-
if: runner.os != 'Windows'

- - name: Cache choosenim
- id: cache-choosenim
- uses: actions/cache@v3
- with:
- path: ~/.choosenim
- key: ${{ runner.os }}-choosenim-${{ matrix.cache-key }}-${{ steps.get-date.outputs.date }}
- restore-keys: |
- ${{ runner.os }}-choosenim-${{ matrix.cache-key }}-

- - uses: jiro4989/setup-nim-action@v1
+ - uses: jiro4989/setup-nim-action@v2
with:
nim-version: '2.0.0' # default is 'stable'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- yes: false
- no-color: yes
- run: nimble build -Y
- run: nimble test -Y
```

### Q&A

#### getAppFilename failed

Please clear cache if you get the following error.

> getAppFilename failed. (Error was: Unable to read /home/runner/.choosenim/current. (Error was: No installation has been chosen. (File missing: /home/runner/.choosenim/current)))
Cache is cleared if you change cache key.

```diff
uses: actions/cache@v3
with:
path: ~/.nimble
- key: ${{ runner.os }}-nimble-${{ hashFiles('*.nimble') }}
+ key: ${{ runner.os }}-nimble-v2-${{ hashFiles('*.nimble') }}
restore-keys: |
- ${{ runner.os }}-nimble-
+ ${{ runner.os }}-nimble-v2-
if: runner.os != 'Windows'
```

Or please remove actions/cache.

```diff
- uses: actions/cache@v3
- with:
- path: ~/.nimble
- key: ${{ runner.os }}-nimble-${{ hashFiles('*.nimble') }}
- restore-keys: |
- ${{ runner.os }}-nimble-
- if: runner.os != 'Windows'
```

## :mag_right:Usage

See [action.yml](action.yml)
Expand All @@ -28,7 +125,7 @@ See [action.yml](action.yml)
```yaml
steps:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: '2.0.0' # default is 'stable'
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,7 +136,7 @@ steps:
`repo-token` is using for [Rate limiting](https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting).
It works without setting this parameter, but please set it if the following error message is returned.

> Error: 403 - {"message":"API rate limit exceeded for nn.nn.nn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
> Error: 403 - {"message":"API rate limit exceeded for nn.nn.nn.nnn. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"<https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}>

### Setup a latest patch version Nim

Expand All @@ -48,7 +145,7 @@ Setup a latest patch version Nim when `nim-version` is `2.n.x` .
```yaml
steps:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: '2.0.x' # ex: 1.0.x, 1.2.x, 1.4.x, 2.0.x ...
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -63,7 +160,7 @@ Setup a latest minor version Nim when `nim-version` is `2.x` .
```yaml
steps:
- uses: actions/checkout@v3
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: '2.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -85,7 +182,7 @@ steps:
restore-keys: |
${{ runner.os }}-nimble-
if: runner.os != 'Windows'
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: nimble build -Y
Expand Down Expand Up @@ -116,7 +213,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup nim
uses: jiro4989/setup-nim-action@v1
uses: jiro4989/setup-nim-action@v2
with:
nim-version: ${{ matrix.nim }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -139,7 +236,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup nim
uses: jiro4989/setup-nim-action@v1
uses: jiro4989/setup-nim-action@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: nimble build -Y
Expand Down Expand Up @@ -170,7 +267,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup nim
uses: jiro4989/setup-nim-action@v1
uses: jiro4989/setup-nim-action@v2
with:
nim-version: ${{ matrix.nim }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -180,8 +277,8 @@ jobs:

### `devel` usage

Use `date` cache-key for speed-up if you want to use `devel`.
See [cache documents](https://github.com/actions/cache) for more information and how to use the cache.
Use `devel` version if you want to use devel compiler of nim.
setup-nim-action will fetch the devel source code and build the nim compiler every time.

```yaml
jobs:
Expand All @@ -195,19 +292,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Get Date
id: get-date
run: echo "::set-output name=date::$(date "+%Y-%m-%d")"
shell: bash
- name: Cache choosenim
id: cache-choosenim
uses: actions/cache@v3
with:
path: ~/.choosenim
key: ${{ runner.os }}-choosenim-${{ matrix.cache-key }}-${{ steps.get-date.outputs.date }}
restore-keys: |
${{ runner.os }}-choosenim-${{ matrix.cache-key }}-
- name: Cache nimble
id: cache-nimble
uses: actions/cache@v3
Expand All @@ -216,9 +300,10 @@ jobs:
key: ${{ runner.os }}-nimble-${{ hashFiles('*.nimble') }}
restore-keys: |
${{ runner.os }}-nimble-
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: "${{ matrix.nim-version }}"
nim-version: devel
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: nimble build
Expand All @@ -234,8 +319,8 @@ This project uses [TypeScript](https://www.typescriptlang.org/).
Run `npm run build` when you edited source code.

```bash
$ vim src/installer.ts
$ npm run build
vim src/installer.ts
npm run build
```

`npm run build` command will output a JavaScript file under the `lib` directory. Please commit this.
Expand All @@ -245,3 +330,4 @@ And please add [test code](https://github.com/jiro4989/setup-nim-action/tree/mas
## :page_facing_up:License

MIT

51 changes: 44 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,58 @@
name: 'Setup Nim environment'
description: 'Setup a Nim environment and add it to the PATH'
author: 'jiro4989'

inputs:
nim-version:
description: >-
The Nim version to download (if necessary)
and use. Example 1.0.2
default: 'stable'
nim-install-directory:
description: >-
The Nim compiler installation directory.
default: '.nim_runtime'
repo-token:
description: 'The GITHUB_TOKEN secret'
required: false
no-color:
description: 'Activate "--noColor" options of choosenim. Example: true'
description: '[Deprecated] unused parameter'
default: false
"yes":
description: 'Activate "--yes" options of choosenim. Example: true'
description: '[Deprecated] unused parameter'
default: false
repo-token:
description: 'The GITHUB_TOKEN secret'
required: false

runs:
using: 'node20'
main: 'lib/setup-nim.js'
using: 'composite'
steps:
- name: Install nim
shell: bash
run: |
"${{ github.action_path }}/install_nim.sh" \
--nim-version "${{ inputs.nim-version }}" \
--nim-install-directory "${{ inputs.nim-install-directory }}" \
--os "${{ runner.os }}" \
--repo-token "${{ inputs.repo-token }}"
- name: Set PATH for Unix
shell: bash
run: |
echo "$PWD/${{ inputs.nim-install-directory }}/bin" >> "$GITHUB_PATH"
echo "$HOME/.nimble/bin" >> "$GITHUB_PATH"
if: runner.os != 'Windows'

- name: Set PATH for Windows
shell: pwsh
run: |
echo "$Pwd\${{ inputs.nim-install-directory }}\bin" >> $Env:GITHUB_PATH
mkdir -Force ~\.nimble\bin
(Resolve-Path ~\.nimble\bin).Path >> $Env:GITHUB_PATH
if: runner.os == 'Windows'

- name: Print nim version
shell: bash
run: nim -v

- name: Print nimble version
shell: bash
run: nimble -v
Loading

0 comments on commit 2910000

Please sign in to comment.