Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 23 additions & 107 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@ on:
workflow_dispatch:

jobs:
check-latest:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v6

- uses: actions/setup-node@v4
- uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

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

- name: Test
Expand All @@ -38,123 +32,45 @@ jobs:
- name: Build
run: npm run build

- name: Run Action
uses: ./
- uses: actions/upload-artifact@v7
with:
check-latest: true
token: ${{ secrets.GITHUB_TOKEN }}
name: build-output
path: lib/

- name: Test if the executable is available
run: v version

ignore-stable-without-latest-flag:
test-action:
needs: build
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
scenario: [check-latest, stable, version]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v6

- uses: actions/setup-node@v4
- uses: actions/download-artifact@v8
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Lint check
if: ${{ matrix.os != 'windows-latest' }}
run: npm run lint
name: build-output
path: lib/

- name: Test
run: npm run test

- name: Build
run: npm run build

- name: Run Action
- name: Run Action (check-latest)
if: matrix.scenario == 'check-latest'
uses: ./
with:
stable: true
check-latest: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Test if the executable is available
run: v version

check-latest-stable:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm ci

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

- name: Test
run: npm run test

- name: Build
run: npm run build

- name: Run Action
- name: Run Action (stable)
if: matrix.scenario == 'stable'
uses: ./
with:
check-latest: true
stable: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Test if the executable is available
run: v version

version:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: [weekly.2024.06]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm ci

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

- name: Test
run: npm run test

- name: Build
run: npm run build

- name: Run Action
- name: Run Action (version)
if: matrix.scenario == 'version'
uses: ./
with:
version: ${{ matrix.version }}
version: '0.5.1'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Test if the executable is available
Expand Down
35 changes: 18 additions & 17 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/github-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function downloadRepository(
authToken: string,
owner: string,
repo: string,
repositoryPath: string,
installDir: string,
ref?: string,
commit?: string
): Promise<void> {
Expand All @@ -25,9 +25,9 @@ export async function downloadRepository(
}

// create directory if not exists
if (!fs.existsSync(repositoryPath)) {
core.info(`Creating directory: ${repositoryPath}`)
fs.mkdirSync(repositoryPath, {recursive: true})
if (!fs.existsSync(installDir)) {
core.info(`Creating directory: ${installDir}`)
fs.mkdirSync(installDir, {recursive: true})
}

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

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

// Move the files
for (const fileName of await fs.promises.readdir(tempRepositoryPath)) {
const sourcePath = path.join(tempRepositoryPath, fileName)
const targetPath = path.join(repositoryPath, fileName)
for (const fileName of await fs.promises.readdir(tempInstallDir)) {
const sourcePath = path.join(tempInstallDir, fileName)
const targetPath = path.join(installDir, fileName)
if (IS_WINDOWS) {
await io.cp(sourcePath, targetPath, {recursive: true}) // Copy on Windows (Windows Defender may have a lock)
} else {
Expand Down
21 changes: 8 additions & 13 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ export async function getVlang({
}: GetVlangRequest): Promise<string> {
const osPlat: string = os.platform()
const osArch: string = translateArchToDistUrl(arch)
const vlangDir = path.join(os.homedir(), 'vlang')
const installDir = path.join(vlangDir, `vlang_${osPlat}_${osArch}`)
const vBinPath = path.join(installDir, 'v')

const repositoryPath = path.join(
process.env.GITHUB_WORKSPACE!,
'vlang',
`vlang_${osPlat}_${osArch}`
)

const vBinPath = path.join(repositoryPath, 'v')

if (fs.existsSync(repositoryPath)) {
return repositoryPath
if (fs.existsSync(installDir)) {
return installDir
}

let correctedRef = version
Expand All @@ -60,17 +55,17 @@ export async function getVlang({
authToken,
VLANG_GITHUB_OWNER,
VLANG_GITHUB_REPO,
repositoryPath,
installDir,
correctedRef
)

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

return repositoryPath
return installDir
}

function translateArchToDistUrl(arch: string): string {
Expand Down
Loading