From 5ecb0dcb918517e340d38047ce9830d45d554373 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 2 Oct 2024 17:33:35 -0300 Subject: [PATCH 1/4] fix(action): properly resolve cn path, closes #10 --- .changes/fix-path-cwd.md | 5 +++++ .github/workflows/test.yml | 3 ++- action.yml | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-path-cwd.md diff --git a/.changes/fix-path-cwd.md b/.changes/fix-path-cwd.md new file mode 100644 index 0000000..14e2660 --- /dev/null +++ b/.changes/fix-path-cwd.md @@ -0,0 +1,5 @@ +--- +"action": patch +--- + +Properly resolve the `cn` path when using the `working-directory` option. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f212323..14f40f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,8 @@ jobs: - name: echo outputs run: echo '${{ steps.version.outputs.stdout }}' - - name: get CLI version (cached) + - name: get CLI version (different cwd) uses: ./ with: command: --version + working-directory: .changes diff --git a/action.yml b/action.yml index 78f61e0..6466352 100644 --- a/action.yml +++ b/action.yml @@ -42,6 +42,7 @@ runs: # key: ${{ runner.os }}-${{ runner.arch }}-cn-${{ env.CURRENT_DATE }} - name: Download CLI (Linux) + id: download-cn-cli shell: bash if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'Linux' working-directory: ${{ inputs.path }} @@ -54,8 +55,10 @@ runs: curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-aarch64 --output cn fi chmod +x cn + echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT - name: Download CLI (macOS) + id: download-cn-cli shell: bash if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'macOS' working-directory: ${{ inputs.path }} @@ -64,8 +67,10 @@ runs: echo "Downloading CLI..." curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/darwin-binary-universal --output cn chmod +x cn + echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT - name: Download CLI (Windows) + id: download-cn-cli shell: bash if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' working-directory: ${{ inputs.path }} @@ -73,6 +78,7 @@ runs: : Download CLI echo "Downloading CLI..." curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/windows-binary-x86_64 --output cn + echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT # - uses: actions/cache/save@v4 # continue-on-error: true @@ -88,8 +94,9 @@ runs: working-directory: ${{ inputs.working-directory }} run: | : cn ${{ inputs.command }} + echo "running `${{ steps.download-cn-cli.outputs.cn-path }}` from '${{ inputs.working-directory }}'" exec 5>&1 - OUTPUT=$(./"${{ inputs.path }}"/cn ${{ inputs.command }} | tee >(cat - >&5)) + OUTPUT=$(${{ steps.download-cn-cli.outputs.cn-path }} ${{ inputs.command }} | tee >(cat - >&5)) echo "stdout<> $GITHUB_OUTPUT echo "$OUTPUT" >> $GITHUB_OUTPUT echo "nEOFn" >> $GITHUB_OUTPUT From d9ad452101c0bd18527c7ff20dc35add7d2ea1f7 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 2 Oct 2024 17:40:24 -0300 Subject: [PATCH 2/4] single download step --- action.yml | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/action.yml b/action.yml index 6466352..54f7cea 100644 --- a/action.yml +++ b/action.yml @@ -49,37 +49,23 @@ runs: run: | : Download CLI echo "Downloading CLI..." - if [[ "${{ runner.arch }}" == "X64" ]]; then - curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-x86_64 --output cn + if [[ "${{ runner.os }}" == "Linux" ]]; then + if [[ "${{ runner.arch }}" == "X64" ]]; then + curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-x86_64 --output cn + else + curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-aarch64 --output cn + fi + elif [[ "${{ runner.os }}" == "macOS" ]]; then + curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/darwin-binary-universal --output cn + elif [[ "${{ runner.os }}" == "Windows" ]]; then + curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/windows-binary-x86_64 --output cn else - curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-aarch64 --output cn + echo "unsupported runner ${{ runner.os }}, only Linux, macOS and Windows are supported" + exit 1 fi chmod +x cn echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT - - name: Download CLI (macOS) - id: download-cn-cli - shell: bash - if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'macOS' - working-directory: ${{ inputs.path }} - run: | - : Download CLI - echo "Downloading CLI..." - curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/darwin-binary-universal --output cn - chmod +x cn - echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT - - - name: Download CLI (Windows) - id: download-cn-cli - shell: bash - if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' - working-directory: ${{ inputs.path }} - run: | - : Download CLI - echo "Downloading CLI..." - curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/windows-binary-x86_64 --output cn - echo "cn-path=$(realpath cn)" >> $GITHUB_OUTPUT - # - uses: actions/cache/save@v4 # continue-on-error: true # with: From fce228071bf16d4283e2f639e5f48d7bcc8bd4a5 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 2 Oct 2024 17:42:12 -0300 Subject: [PATCH 3/4] fix condition --- action.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 54f7cea..5e0b9b2 100644 --- a/action.yml +++ b/action.yml @@ -24,15 +24,15 @@ outputs: runs: using: 'composite' steps: - - name: Get current date - shell: bash - run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - if: runner.os == 'Linux' || runner.os == 'macOS' +# - name: Get current date +# shell: bash +# run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV +# if: runner.os == 'Linux' || runner.os == 'macOS' - - name: Get current date - shell: pwsh - if: runner.os == 'Windows' - run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append +# - name: Get current date +# shell: pwsh +# if: runner.os == 'Windows' +# run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append # - name: Cache CLI # id: restore-cache @@ -44,7 +44,7 @@ runs: - name: Download CLI (Linux) id: download-cn-cli shell: bash - if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'Linux' + if: steps.restore-cache.outputs.cache-hit != 'true' working-directory: ${{ inputs.path }} run: | : Download CLI From d40bdbdf84db48a4aa4b466883b82a29c2aa8126 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 2 Oct 2024 17:45:57 -0300 Subject: [PATCH 4/4] fix echo --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 5e0b9b2..8ed355c 100644 --- a/action.yml +++ b/action.yml @@ -79,8 +79,8 @@ runs: CN_API_KEY: ${{ inputs.api-key }} working-directory: ${{ inputs.working-directory }} run: | - : cn ${{ inputs.command }} - echo "running `${{ steps.download-cn-cli.outputs.cn-path }}` from '${{ inputs.working-directory }}'" + : run cn ${{ inputs.command }} + echo "running \"${{ steps.download-cn-cli.outputs.cn-path }}\" from '${{ inputs.working-directory }}'" exec 5>&1 OUTPUT=$(${{ steps.download-cn-cli.outputs.cn-path }} ${{ inputs.command }} | tee >(cat - >&5)) echo "stdout<> $GITHUB_OUTPUT