-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Install on Windows is very slow (#393)
* Fix Install on Windows is very slow * Add unit test * Improve readability * Add e2e test * fix lint * Fix unit tests * Fix unit tests * limit to github hosted runners * test hosted version of go * AzDev environment * rename lnkSrc * refactor conditions * improve tests * refactoring * Fix e2e test * improve isHosted readability
- Loading branch information
Showing
5 changed files
with
291 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Validate Windows installation | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- '**.md' | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
|
||
jobs: | ||
create-link-if-not-default: | ||
runs-on: windows-latest | ||
name: 'Validate if symlink is created' | ||
strategy: | ||
matrix: | ||
cache: [false, true] | ||
go: [1.20.1] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: 'Setup ${{ matrix.cache }}, cache: ${{ matrix.go }}' | ||
uses: ./ | ||
with: | ||
go-version: ${{ matrix.go }} | ||
cache: ${{ matrix.cache }} | ||
|
||
- name: 'Drive C: should have zero size link' | ||
run: | | ||
du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64' | ||
# make sure drive c: contains only a link | ||
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t') | ||
if [ $size -ne 0 ];then | ||
echo 'Size of the link created on drive c: must be 0' | ||
exit 1 | ||
fi | ||
shell: bash | ||
|
||
# Drive D: is small, take care the action does not eat up the space | ||
- name: 'Drive D: space usage should be below 1G' | ||
run: | | ||
du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64' | ||
size=$(du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t') | ||
# make sure archive does not take lot of space | ||
if [ $size -gt 999 ];then | ||
echo 'Size of installed on drive d: go is too big'; | ||
exit 1 | ||
fi | ||
shell: bash | ||
|
||
# make sure the Go installation has not been changed to the end user | ||
- name: Test paths and environments | ||
run: | | ||
echo $PATH | ||
which go | ||
go version | ||
go env | ||
if [ $(which go) != '/c/hostedtoolcache/windows/go/${{ matrix.go }}/x64/bin/go' ];then | ||
echo 'which go should return "/c/hostedtoolcache/windows/go/${{ matrix.go }}/x64/bin/go"' | ||
exit 1 | ||
fi | ||
if [ $(go env GOROOT) != 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64' ];then | ||
echo 'go env GOROOT should return "C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64"' | ||
exit 1 | ||
fi | ||
shell: bash | ||
|
||
find-default-go: | ||
name: 'Find default go version' | ||
runs-on: windows-latest | ||
outputs: | ||
version: ${{ steps.goversion.outputs.version }} | ||
steps: | ||
- run: | | ||
version=`go env GOVERSION|sed s/^go//` | ||
echo "default go version: $version" | ||
echo "version=$version" >> "$GITHUB_OUTPUT" | ||
id: goversion | ||
shell: bash | ||
dont-create-link-if-default: | ||
name: 'Validate if symlink is not created for default go' | ||
runs-on: windows-latest | ||
needs: find-default-go | ||
strategy: | ||
matrix: | ||
cache: [false, true] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: 'Setup default go, cache: ${{ matrix.cache }}' | ||
uses: ./ | ||
with: | ||
go-version: ${{ needs.find-default-go.outputs.version }} | ||
cache: ${{ matrix.cache }} | ||
|
||
- name: 'Drive C: should have Go installation, cache: ${{ matrix.cache}}' | ||
run: | | ||
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64'|cut -f1 -d$'\t') | ||
if [ $size -eq 0 ];then | ||
echo 'Size of the hosted go installed on drive c: must be above zero' | ||
exit 1 | ||
fi | ||
shell: bash | ||
|
||
- name: 'Drive D: should not have Go installation, cache: ${{ matrix.cache}}' | ||
run: | | ||
if [ -e 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64' ];then | ||
echo 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64 should not exist for hosted version of go'; | ||
exit 1 | ||
fi | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'fs'; | ||
import * as io from '@actions/io'; | ||
import * as tc from '@actions/tool-cache'; | ||
import path from 'path'; | ||
|
||
describe('Windows performance workaround', () => { | ||
let mkdirSpy: jest.SpyInstance; | ||
let symlinkSpy: jest.SpyInstance; | ||
let statSpy: jest.SpyInstance; | ||
let readdirSpy: jest.SpyInstance; | ||
let writeFileSpy: jest.SpyInstance; | ||
let rmRFSpy: jest.SpyInstance; | ||
let mkdirPSpy: jest.SpyInstance; | ||
let cpSpy: jest.SpyInstance; | ||
|
||
let runnerToolCache: string | undefined; | ||
beforeEach(() => { | ||
mkdirSpy = jest.spyOn(fs, 'mkdir'); | ||
symlinkSpy = jest.spyOn(fs, 'symlinkSync'); | ||
statSpy = jest.spyOn(fs, 'statSync'); | ||
readdirSpy = jest.spyOn(fs, 'readdirSync'); | ||
writeFileSpy = jest.spyOn(fs, 'writeFileSync'); | ||
rmRFSpy = jest.spyOn(io, 'rmRF'); | ||
mkdirPSpy = jest.spyOn(io, 'mkdirP'); | ||
cpSpy = jest.spyOn(io, 'cp'); | ||
|
||
// default implementations | ||
// @ts-ignore - not implement unused methods | ||
statSpy.mockImplementation(() => ({ | ||
isDirectory: () => true | ||
})); | ||
readdirSpy.mockImplementation(() => []); | ||
writeFileSpy.mockImplementation(() => {}); | ||
mkdirSpy.mockImplementation(() => {}); | ||
symlinkSpy.mockImplementation(() => {}); | ||
rmRFSpy.mockImplementation(() => Promise.resolve()); | ||
mkdirPSpy.mockImplementation(() => Promise.resolve()); | ||
cpSpy.mockImplementation(() => Promise.resolve()); | ||
|
||
runnerToolCache = process.env['RUNNER_TOOL_CACHE']; | ||
}); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
process.env['RUNNER_TOOL_CACHE'] = runnerToolCache; | ||
}); | ||
// cacheWindowsToolkitDir depends on implementation of tc.cacheDir | ||
// with the assumption that target dir is passed by RUNNER_TOOL_CACHE environment variable | ||
// Make sure the implementation has not been changed | ||
it('addExecutablesToCache should depend on env[RUNNER_TOOL_CACHE]', async () => { | ||
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache1'; | ||
const cacheDir1 = await tc.cacheDir('/qzx', 'go', '1.2.3', 'arch'); | ||
expect(cacheDir1).toBe( | ||
path.join('/', 'faked-hostedtoolcache1', 'go', '1.2.3', 'arch') | ||
); | ||
|
||
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache2'; | ||
const cacheDir2 = await tc.cacheDir('/qzx', 'go', '1.2.3', 'arch'); | ||
expect(cacheDir2).toBe( | ||
path.join('/', 'faked-hostedtoolcache2', 'go', '1.2.3', 'arch') | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters