forked from crabnebula-dev/cloud-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
94 lines (85 loc) · 3.2 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
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)
shell: bash
if: steps.restore-cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
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
else
curl -L https://cdn.crabnebula.app/download/crabnebula/cn-cli/latest/platform/linux-binary-aarch64 --output cn
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
- uses: actions/cache/save@v4
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: |
: cn ${{ inputs.command }}
exec 5>&1
OUTPUT=$(./"${{ inputs.path }}"/cn ${{ inputs.command }} | tee >(cat - >&5))
echo "stdout<<nEOFn" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT