Skip to content

Commit

Permalink
Support installation of sqlcmd
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Jul 27, 2024
1 parent d08a956 commit 03c305c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Continuous Integration

on:
pull_request:
push:

permissions:
contents: read

jobs:
test:
name: Tests
strategy:
matrix:
os:
# ignore ARM64 flavours
- macos-12-large
- macos-13-large
- macos-14-large
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
- windows-2019
- windows-2022

runs-on: ${{ matrix.os }}
steps:
# cloning into "root" does not work when trying to call the action from itself
# inspired by Microsoft: https://github.com/microsoft/action-python/blob/c8ec939994d7ed2ec77b7bbe59ed5f5b72fb5607/.github/workflows/test.yml#L21
- name: Checkout
uses: actions/checkout@v4
with:
path: action
clean: true

- name: Run Action
uses: ./action
with:
components: sqlcmd

- name: Run tests
run: |
action/test.ps1
shell: pwsh
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Setup MSSQL"
branding:
icon: "database"
color: "yellow"
description: "Installs an MSSQL server and client"
inputs:
components:
description: "The components to install"
required: true
runs:
using: "composite"
steps:
- shell: pwsh
run: |
$params = @{
Components = ("${{ inputs.components }}" -split ",").Trim()
}
${{ github.action_path }}/install.ps1 @params
31 changes: 31 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
param (
[ValidateSet("sqlcmd")]
[string[]]$Components
)

if ("sqlcmd" -in $Components) {
if ($IsMacOS) {
Write-Output "Installing sqlcmd tools"
brew install sqlcmd
}

if ($IsLinux) {
$osRelease = Get-Content -Path "/etc/os-release" | Out-String
$osRelease -match 'VERSION_ID="(\d+\.\d+)"' | Out-Null
$version = $matches[1]

if ($version -eq "24.04") {
# for maintenance reasons, sqlcmd has been removed from the runner image
# but a dedicated build is also not yet available, so we are using the Ubuntu 22.04 build
Write-Output "Installing sqlcmd tools"

$DownloadPath = "/tmp/sqlcmd.deb"
Invoke-WebRequest "https://packages.microsoft.com/ubuntu/22.04/prod/pool/main/s/sqlcmd/sqlcmd_1.5.0-1_jammy_all.deb" -OutFile $DownloadPath
& sudo dpkg -i $DownloadPath
Remove-Item $DownloadPath
}
}

# Linux and Windows runner already contain sqlclient tools
Write-Output "sqlclient tools are installed"
}
6 changes: 6 additions & 0 deletions test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (Get-Command sqlcmd -ErrorAction SilentlyContinue) {
Write-Output "sqlcmd command exists."
} else {
Write-Output "sqlcmd command does not exist."
exit 1
}

0 comments on commit 03c305c

Please sign in to comment.