-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
165 lines (145 loc) · 5.43 KB
/
action.yml
File metadata and controls
165 lines (145 loc) · 5.43 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: 'Setup DBC'
description: 'Install dbc CLI, authenticate, and install drivers'
author: 'Columnar'
inputs:
version:
description: 'Version of dbc CLI to install (e.g., v1.2.3 or "latest")'
required: false
default: 'latest'
api-key:
description: 'API key for authenticating private driver installations'
required: false
drivers:
description: 'Comma-separated list of drivers to install (e.g., "postgres,mysql")'
required: false
driver-list-file:
description: 'Path to dbc.toml config file for driver installation'
required: false
default: 'dbc.toml'
skip-drivers:
description: 'Skip driver installation even if drivers or driver-list-file are specified'
required: false
default: 'false'
outputs:
version:
description: 'The installed version of dbc CLI'
value: ${{ steps.install.outputs.version || steps.install-win.outputs.version }}
cache-hit:
description: 'Whether the dbc CLI was restored from cache'
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: 'composite'
steps:
- name: Determine cache key
shell: bash
id: cache-key
run: |
echo "key=dbc-cli-${{ runner.os }}-${{ inputs.version }}" >> $GITHUB_OUTPUT
- name: Cache dbc CLI
id: cache
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
# Include all possible cache paths for different OSes
# Missing paths are silently ignored by the cache action
path: |
~/.local/bin/dbc
~/.local/bin/dbc.exe
~/.local/bin/dbc-install-dir.txt
~/Library/Application Support/dbc
${{ runner.temp }}/dbc
key: ${{ steps.cache-key.outputs.key }}
- name: Install dbc CLI (Unix)
id: install-unix
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
${{ github.action_path }}/install-unix.sh "${{ inputs.version }}"
- name: Install dbc CLI (Windows)
id: install-windows
if: runner.os == 'Windows' && steps.cache.outputs.cache-hit != 'true'
shell: pwsh
run: |
& "${{ github.action_path }}/install-windows.ps1" -Version "${{ inputs.version }}"
- name: Add dbc to PATH (Unix)
if: runner.os != 'Windows' && (steps.cache.outputs.cache-hit == 'true' || steps.install-unix.outcome == 'success')
shell: bash
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Add dbc to PATH (Windows, cache hit)
if: runner.os == 'Windows' && steps.cache.outputs.cache-hit == 'true'
shell: pwsh
run: |
$sideFile = Join-Path $env:USERPROFILE ".local\bin\dbc-install-dir.txt"
if (Test-Path $sideFile) {
$installDir = (Get-Content $sideFile -Raw).Trim()
} else {
$installDir = Join-Path $env:USERPROFILE ".local\bin"
}
if ($installDir) {
$installDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
} else {
Write-Error "dbc-install-dir.txt is empty; cannot add dbc to PATH"
}
- name: Get installed version
id: install
if: runner.os != 'Windows'
shell: bash
run: |
VERSION=$(dbc --version | grep -o 'v[0-9]*\.[0-9]*\.[0-9]*' | head -n1 || echo "unknown")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Get installed version (Windows)
id: install-win
if: runner.os == 'Windows'
shell: pwsh
run: |
try {
$v = & dbc --version 2>&1 | Select-String 'v\d+\.\d+\.\d+' | ForEach-Object { $_.Matches[0].Value } | Select-Object -First 1
} catch { Write-Warning "dbc --version failed: $_" }
if (-not $v) { $v = 'unknown' }
"version=$v" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Authenticate with API key
if: inputs.api-key != '' && runner.os != 'Windows'
shell: bash
env:
INPUT_API_KEY: ${{ inputs.api-key }}
run: |
dbc auth login --api-key "$INPUT_API_KEY"
- name: Authenticate with API key (Windows)
if: inputs.api-key != '' && runner.os == 'Windows'
shell: pwsh
env:
INPUT_API_KEY: ${{ inputs.api-key }}
run: |
dbc auth login --api-key "$env:INPUT_API_KEY"
- name: Install drivers from list
if: inputs.drivers != '' && inputs.skip-drivers != 'true'
shell: bash
run: |
IFS=',' read -ra DRIVER_ARRAY <<< "${{ inputs.drivers }}"
FAILED_DRIVERS=()
for driver in "${DRIVER_ARRAY[@]}"; do
driver=$(echo "$driver" | xargs)
echo "Installing driver: $driver"
if ! dbc install "$driver"; then
FAILED_DRIVERS+=("$driver")
fi
done
if [ ${#FAILED_DRIVERS[@]} -ne 0 ]; then
echo "::error::Failed to install drivers: ${FAILED_DRIVERS[*]}"
exit 2
fi
- name: Install drivers from config file
if: inputs.drivers == '' && inputs.skip-drivers != 'true'
shell: bash
run: |
if [ -f "${{ inputs.driver-list-file }}" ]; then
echo "Installing drivers from ${{ inputs.driver-list-file }}"
if ! dbc sync -p "${{ inputs.driver-list-file }}"; then
echo "::error::Failed to sync drivers from config file"
exit 2
fi
else
echo "No config file found at ${{ inputs.driver-list-file }}, skipping driver installation"
fi
branding:
icon: 'download'
color: 'blue'