-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
99 lines (92 loc) · 3.68 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: 'cn-cloud-release'
description: 'CrabNebula Cloud Release GitHub Action'
inputs:
command:
description: 'The command to execute using the CrabNebula Cloud CLI'
required: true
api-key:
description: 'API key with write permissions for CrabNebula Cloud'
required: true
path:
description: 'Optional path to a directory where the CLI should be downloaded, needs to be a valid path (Unix syntax)'
required: false
default: '.'
working-directory:
description: 'Current working directory to use when running the CLI'
required: false
default: '.'
outputs:
stdout:
description: "The stdout of the CLI"
value: ${{ steps.run-command.outputs.stdout }}
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: 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
# uses: actions/cache/restore@v4
# with:
# path: ${{ inputs.path }}/cn
# 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'
working-directory: ${{ inputs.path }}
env:
# Note: be careful about line-breaks for this parameter. Curl will break when they end up being sent as part of the header.
USER_AGENT: >-
${{
format(
'cloud-release{0} ({1}; {2})',
github.action_ref && format('/{0}',github.action_ref),
runner.os,
runner.arch
)
}}
run: |
: Download CLI
echo "Downloading CLI..."
if [[ "${{ runner.os }}" == "Linux" ]]; then
if [[ "${{ runner.arch }}" == "X64" ]]; then
curl -A "$USER_AGENT" -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-x86_64 --output cn
else
curl -A "$USER_AGENT" -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-aarch64 --output cn
fi
elif [[ "${{ runner.os }}" == "macOS" ]]; then
curl -A "$USER_AGENT" -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/darwin-binary-universal --output cn
elif [[ "${{ runner.os }}" == "Windows" ]]; then
curl -A "$USER_AGENT" -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/windows-binary-x86_64 --output cn
else
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
# - uses: actions/cache/save@v4
# continue-on-error: true
# with:
# path: ${{ inputs.path }}/cn
# key: ${{ steps.restore-cache.outputs.cache-primary-key }}
- name: "Run Command"
id: run-command
shell: bash
env:
CN_API_KEY: ${{ inputs.api-key }}
working-directory: ${{ inputs.working-directory }}
run: |
: 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<<nEOFn" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT