Skip to content

Commit 0a679bf

Browse files
authored
Merge pull request vlang#10 from cadamsdev/issue-7
fix: Move V installation out of current working directory
2 parents 51668e8 + b6237a3 commit 0a679bf

File tree

5 files changed

+60
-148
lines changed

5 files changed

+60
-148
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,20 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
check-latest:
14-
strategy:
15-
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
17-
runs-on: ${{ matrix.os }}
18-
13+
build:
14+
runs-on: ubuntu-latest
1915
steps:
20-
- uses: actions/checkout@v4
21-
with:
22-
fetch-depth: 0
16+
- uses: actions/checkout@v6
2317

24-
- uses: actions/setup-node@v4
18+
- uses: actions/setup-node@v6
2519
with:
2620
node-version: '20'
21+
cache: 'npm'
2722

2823
- name: Install dependencies
2924
run: npm ci
3025

3126
- name: Lint check
32-
if: ${{ matrix.os != 'windows-latest' }}
3327
run: npm run lint
3428

3529
- name: Test
@@ -38,123 +32,45 @@ jobs:
3832
- name: Build
3933
run: npm run build
4034

41-
- name: Run Action
42-
uses: ./
35+
- uses: actions/upload-artifact@v7
4336
with:
44-
check-latest: true
45-
token: ${{ secrets.GITHUB_TOKEN }}
37+
name: build-output
38+
path: lib/
4639

47-
- name: Test if the executable is available
48-
run: v version
49-
50-
ignore-stable-without-latest-flag:
40+
test-action:
41+
needs: build
5142
strategy:
5243
matrix:
5344
os: [ubuntu-latest, windows-latest, macos-latest]
45+
scenario: [check-latest, stable, version]
5446
runs-on: ${{ matrix.os }}
55-
5647
steps:
57-
- uses: actions/checkout@v4
58-
with:
59-
fetch-depth: 0
48+
- uses: actions/checkout@v6
6049

61-
- uses: actions/setup-node@v4
50+
- uses: actions/download-artifact@v8
6251
with:
63-
node-version: '20'
64-
65-
- name: Install dependencies
66-
run: npm ci
67-
68-
- name: Lint check
69-
if: ${{ matrix.os != 'windows-latest' }}
70-
run: npm run lint
52+
name: build-output
53+
path: lib/
7154

72-
- name: Test
73-
run: npm run test
74-
75-
- name: Build
76-
run: npm run build
77-
78-
- name: Run Action
55+
- name: Run Action (check-latest)
56+
if: matrix.scenario == 'check-latest'
7957
uses: ./
8058
with:
81-
stable: true
59+
check-latest: true
8260
token: ${{ secrets.GITHUB_TOKEN }}
8361

84-
- name: Test if the executable is available
85-
run: v version
86-
87-
check-latest-stable:
88-
strategy:
89-
matrix:
90-
os: [ubuntu-latest, windows-latest, macos-latest]
91-
runs-on: ${{ matrix.os }}
92-
93-
steps:
94-
- uses: actions/checkout@v4
95-
with:
96-
fetch-depth: 0
97-
98-
- uses: actions/setup-node@v4
99-
with:
100-
node-version: '20'
101-
102-
- name: Install dependencies
103-
run: npm ci
104-
105-
- name: Lint check
106-
if: ${{ matrix.os != 'windows-latest' }}
107-
run: npm run lint
108-
109-
- name: Test
110-
run: npm run test
111-
112-
- name: Build
113-
run: npm run build
114-
115-
- name: Run Action
62+
- name: Run Action (stable)
63+
if: matrix.scenario == 'stable'
11664
uses: ./
11765
with:
118-
check-latest: true
11966
stable: true
12067
token: ${{ secrets.GITHUB_TOKEN }}
12168

122-
- name: Test if the executable is available
123-
run: v version
124-
125-
version:
126-
strategy:
127-
matrix:
128-
os: [ubuntu-latest, windows-latest, macos-latest]
129-
version: [weekly.2024.06]
130-
runs-on: ${{ matrix.os }}
131-
132-
steps:
133-
- uses: actions/checkout@v4
134-
with:
135-
fetch-depth: 0
136-
137-
- uses: actions/setup-node@v4
138-
with:
139-
node-version: '20'
140-
141-
- name: Install dependencies
142-
run: npm ci
143-
144-
- name: Lint check
145-
if: ${{ matrix.os != 'windows-latest' }}
146-
run: npm run lint
147-
148-
- name: Test
149-
run: npm run test
150-
151-
- name: Build
152-
run: npm run build
153-
154-
- name: Run Action
69+
- name: Run Action (version)
70+
if: matrix.scenario == 'version'
15571
uses: ./
15672
with:
157-
version: ${{ matrix.version }}
73+
version: '0.5.1'
15874
token: ${{ secrets.GITHUB_TOKEN }}
15975

16076
- name: Test if the executable is available

dist/index.js

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github-api-helper.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function downloadRepository(
1414
authToken: string,
1515
owner: string,
1616
repo: string,
17-
repositoryPath: string,
17+
installDir: string,
1818
ref?: string,
1919
commit?: string
2020
): Promise<void> {
@@ -25,9 +25,9 @@ export async function downloadRepository(
2525
}
2626

2727
// create directory if not exists
28-
if (!fs.existsSync(repositoryPath)) {
29-
core.info(`Creating directory: ${repositoryPath}`)
30-
fs.mkdirSync(repositoryPath, {recursive: true})
28+
if (!fs.existsSync(installDir)) {
29+
core.info(`Creating directory: ${installDir}`)
30+
fs.mkdirSync(installDir, {recursive: true})
3131
}
3232

3333
// Download the archive
@@ -39,13 +39,13 @@ export async function downloadRepository(
3939
// Write archive to disk
4040
core.info('Writing archive to disk')
4141
const uniqueId = uuid()
42-
const archivePath = path.join(repositoryPath, `${uniqueId}.tar.gz`)
42+
const archivePath = path.join(installDir, `${uniqueId}.tar.gz`)
4343
await fs.promises.writeFile(archivePath, archiveData)
4444
archiveData = Buffer.from('') // Free memory
4545

4646
// Extract archive
4747
core.info('Extracting the archive')
48-
const extractPath = path.join(repositoryPath, uniqueId)
48+
const extractPath = path.join(installDir, uniqueId)
4949
await io.mkdirP(extractPath)
5050
if (IS_WINDOWS) {
5151
await toolCache.extractZip(archivePath, extractPath)
@@ -63,12 +63,12 @@ export async function downloadRepository(
6363
)
6464
const archiveVersion = archiveFileNames[0] // The top-level folder name includes the short SHA
6565
core.info(`Resolved version ${archiveVersion}`)
66-
const tempRepositoryPath = path.join(extractPath, archiveVersion)
66+
const tempInstallDir = path.join(extractPath, archiveVersion)
6767

6868
// Move the files
69-
for (const fileName of await fs.promises.readdir(tempRepositoryPath)) {
70-
const sourcePath = path.join(tempRepositoryPath, fileName)
71-
const targetPath = path.join(repositoryPath, fileName)
69+
for (const fileName of await fs.promises.readdir(tempInstallDir)) {
70+
const sourcePath = path.join(tempInstallDir, fileName)
71+
const targetPath = path.join(installDir, fileName)
7272
if (IS_WINDOWS) {
7373
await io.cp(sourcePath, targetPath, {recursive: true}) // Copy on Windows (Windows Defender may have a lock)
7474
} else {

src/installer.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ export async function getVlang({
2525
}: GetVlangRequest): Promise<string> {
2626
const osPlat: string = os.platform()
2727
const osArch: string = translateArchToDistUrl(arch)
28+
const vlangDir = path.join(os.homedir(), 'vlang')
29+
const installDir = path.join(vlangDir, `vlang_${osPlat}_${osArch}`)
30+
const vBinPath = path.join(installDir, 'v')
2831

29-
const repositoryPath = path.join(
30-
process.env.GITHUB_WORKSPACE!,
31-
'vlang',
32-
`vlang_${osPlat}_${osArch}`
33-
)
34-
35-
const vBinPath = path.join(repositoryPath, 'v')
36-
37-
if (fs.existsSync(repositoryPath)) {
38-
return repositoryPath
32+
if (fs.existsSync(installDir)) {
33+
return installDir
3934
}
4035

4136
let correctedRef = version
@@ -60,17 +55,17 @@ export async function getVlang({
6055
authToken,
6156
VLANG_GITHUB_OWNER,
6257
VLANG_GITHUB_REPO,
63-
repositoryPath,
58+
installDir,
6459
correctedRef
6560
)
6661

6762
if (!fs.existsSync(vBinPath)) {
6863
core.info('Running make...')
6964
// eslint-disable-next-line no-console
70-
console.log(execSync(`make`, {cwd: repositoryPath}).toString())
65+
console.log(execSync(`make`, {cwd: installDir}).toString())
7166
}
7267

73-
return repositoryPath
68+
return installDir
7469
}
7570

7671
function translateArchToDistUrl(arch: string): string {

0 commit comments

Comments
 (0)