Action for installing ODBC drivers for mssql exactly according to Microsoft's instructions.
This action runs a python script that scrapes Microsoft's official instructions per the requested distribution and executes them. By default we remove "exit\n" cases that are found in the instructions.
inputs:
ODBC_VERSION:
description: 'ODBC version to install (18 or 17 validated)'
default: "18"
DISTRO:
description: 'Distribution (Alpine, Debian, RHEL and Oracle Linux, SLES, Ubuntu)'
default: Ubuntu
DOCS_URL:
description: 'URL to the docs page to scrape instructions from'
default: "https://raw.githubusercontent.com/MicrosoftDocs/sql-docs/live/docs/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server.md"
REMOVE_EXITS:
default: 'true'
description: 'Remove exit statements from the script (they break the workflow)'
# minimal
- uses: Yarden-zamir/install-mssql-odbc@main
# all inputs
- uses: Yarden-zamir/install-mssql-odbc@main
with:
ODBC_VERSION: 17
DISTRO: Alpine
DOCS_URL: https://yarden-zamir.com/alternate-docs-path.md
REMOVE_EXITS: true
Taking the exact example from microsoft here
- uses: Yarden-zamir/install-mssql-odbc@main
- run: pip install pyodbc
- name: Connect
shell: python
run: |
import pyodbc
# Some other example server values are
# server = 'localhost\sqlexpress' # for a named instance
# server = 'myserver,port' # to specify an alternate port
server = 'tcp:myserver.database.windows.net'
database = 'mydb'
username = 'myusername'
password = 'mypassword'
# ENCRYPT defaults to yes starting in ODBC Driver 18. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks.
cnxn = pyodbc.connect('DRIVER={ODBC Driver 18 for SQL Server};SERVER='+server+';DATABASE='+database+';ENCRYPT=yes;UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
- name: Run query
shell: python
run: |
#Sample select query
cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()