Skip to content

Commit

Permalink
ci: improve github actions (#1573)
Browse files Browse the repository at this point in the history
* ci: use built-in npm caching

The setup-node action automatically stores caches for NPM and uses the
same logic as the current action implementation, so there's no need to
duplicate it in the action definition.

* ci: remove npm upgrade step

The npm upgrade steps in CI only run if the matrix version for node is 6.x
but 6.x is not a tested version of node in any of the matrix definitions.

* ci: only checkout latest history for lint step

The linting step does not need the entire repository history to
run. Only checkout the minimal history to allow faster lint step.

* ci: use setup-sqlserver action for installing SQL Server
  • Loading branch information
dhensby authored Aug 11, 2024
1 parent af21197 commit 03777a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 159 deletions.
171 changes: 12 additions & 159 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@ jobs:
steps:
- uses: actions/[email protected]

with:
fetch-depth: 0
- name: Use Node.js 18
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci
- run: npm run lint
Expand All @@ -58,6 +45,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Generate TLS Certificate
run: |
Expand All @@ -71,22 +59,6 @@ jobs:
shell: bash
run: cp -f test/config.ci.ts test/config.ts

- name: Upgrade npm
run: npm install -g npm
if: ${{ matrix.node-version == '6.x' }}

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci

- name: run unit tests
Expand Down Expand Up @@ -154,59 +126,10 @@ jobs:

steps:
- name: Install SQL Server ${{ matrix.mssql-version }}
shell: pwsh
run: |
Push-Location C:\temp
$exe_link, $box_link, $update_link, $update_download_link = '', '', '', ''
switch (${{ matrix.mssql-version }}) {
'2022' {
$exe_link = 'https://download.microsoft.com/download/3/8/d/38de7036-2433-4207-8eae-06e247e17b25/SQLServer2022-DEV-x64-ENU.exe'
$box_link = 'https://download.microsoft.com/download/3/8/d/38de7036-2433-4207-8eae-06e247e17b25/SQLServer2022-DEV-x64-ENU.box'
$update_link = 'https://www.microsoft.com/en-us/download/details.aspx?id=105013'
}
'2019' {
$exe_link = 'https://download.microsoft.com/download/8/4/c/84c6c430-e0f5-476d-bf43-eaaa222a72e0/SQLServer2019-DEV-x64-ENU.exe'
$box_link = 'https://download.microsoft.com/download/8/4/c/84c6c430-e0f5-476d-bf43-eaaa222a72e0/SQLServer2019-DEV-x64-ENU.box'
$update_link = 'https://www.microsoft.com/en-us/download/details.aspx?id=100809'
}
'2017' {
$exe_link = 'https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLServer2017-DEV-x64-ENU.exe'
$box_link = 'https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLServer2017-DEV-x64-ENU.box'
$update_link = 'https://www.microsoft.com/en-us/download/details.aspx?id=56128'
}
'2016' {
$exe_link = 'https://download.microsoft.com/download/4/1/A/41AD6EDE-9794-44E3-B3D5-A1AF62CD7A6F/sql16_sp2_dlc/en-us/SQLServer2016SP2-FullSlipstream-DEV-x64-ENU.exe'
$box_link = 'https://download.microsoft.com/download/4/1/A/41AD6EDE-9794-44E3-B3D5-A1AF62CD7A6F/sql16_sp2_dlc/en-us/SQLServer2016SP2-FullSlipstream-DEV-x64-ENU.box'
$update_download_link = 'https://download.microsoft.com/download/a/7/7/a77b5753-8fe7-4804-bfc5-591d9a626c98/SQLServer2016SP3-KB5003279-x64-ENU.exe'
}
default {
Write-Error "Invalid SQL Server version specified: ${{ matrix.mssql-version }}"
Exit 1
}
}
if (${{ matrix.mssql-version }} -ne '2016') {
$dl_links = ((Invoke-WebRequest -Uri $update_link).Links | Where-Object {$_.href -like 'https://download.microsoft.com/*'})
if ($dl_links.count -gt 0) {
$update_download_link = [System.Uri]::new($dl_links[0].href)
} else {
Write-Error "Download link not found"
Exit 1
}
echo $update_download_link
}
Invoke-WebRequest -Uri $update_download_link -Outfile sqlupdate.exe
Invoke-WebRequest -Uri $exe_link -OutFile sqlsetup.exe
Invoke-WebRequest -Uri $box_link -OutFile sqlsetup.box
Start-Process -Wait -FilePath ./sqlsetup.exe -ArgumentList /qs, /x:setup
.\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=1 /UpdateSource=C:\temp /SQLSVCACCOUNT='NT SERVICE\MSSQLSERVER' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS /SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS /SECURITYMODE=SQL /SAPWD="yourStrong(!)Password"
Pop-Location
uses: tediousjs/setup-sqlserver@v2
with:
sqlserver-version: ${{ matrix.mssql-version }}
install-updates: true

- uses: actions/[email protected]

Expand All @@ -215,6 +138,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dbatools
shell: powershell
Expand Down Expand Up @@ -254,23 +178,6 @@ jobs:
shell: bash
run: cp -f test/config.ci.ts test/config.ts

- name: Upgrade npm
run: npm install -g npm
if: ${{ matrix.node-version == '6.x' }}

- name: Determine npm cache directory
id: npm-cache
shell: bash
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci

- name: run unit tests
Expand Down Expand Up @@ -340,17 +247,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci

Expand Down Expand Up @@ -384,18 +281,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci

Expand Down Expand Up @@ -431,18 +317,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci

Expand Down Expand Up @@ -479,18 +354,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci

Expand Down Expand Up @@ -523,18 +387,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18

- name: Determine npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/[email protected]
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
cache: 'npm'

- run: npm ci

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: actions/[email protected]
with:
node-version: 18
cache: 'npm'

- name: Tag latest release
run: |
Expand Down

0 comments on commit 03777a7

Please sign in to comment.