Skip to content

Commit

Permalink
Merge pull request #11 from crabnebula-dev/fix/path-cwd-usage
Browse files Browse the repository at this point in the history
fix(action): properly resolve cn path, closes #10
  • Loading branch information
lucasfernog-crabnebula authored Oct 2, 2024
2 parents 4c63fcf + d40bdbd commit e3c5208
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-path-cwd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"action": patch
---

Properly resolve the `cn` path when using the `working-directory` option.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 26 additions & 33 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,37 +42,29 @@ 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'
if: steps.restore-cache.outputs.cache-hit != 'true'
working-directory: ${{ inputs.path }}
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
- name: Download CLI (macOS)
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
- name: Download CLI (Windows)
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
Expand All @@ -87,9 +79,10 @@ runs:
CN_API_KEY: ${{ inputs.api-key }}
working-directory: ${{ inputs.working-directory }}
run: |
: cn ${{ inputs.command }}
: 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<<nEOFn" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT

0 comments on commit e3c5208

Please sign in to comment.