Skip to content

Commit

Permalink
Add include-templates option (default false). Fix cache. (#80)
Browse files Browse the repository at this point in the history
* Add include-templates option (default false). Fix cache failing to resolve.

* Update readme about optional templates.

* Add include-templates as part of test matrix

* Fix include-templates matrix
  • Loading branch information
plink-plonk-will authored Mar 21, 2024
1 parent d3fbddf commit 1dc3741
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 91 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

jobs:
tests:
name: 🧪 Test on ${{ matrix.os }}, .NET=${{ matrix.use-dotnet }}
name: 🧪 Test on ${{ matrix.os }}, .NET=${{ matrix.use-dotnet }}, include-templates=${{ matrix.include-templates }}
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -26,6 +26,7 @@ jobs:
# Put the operating systems you want to run on here.
os: [ubuntu-latest, macos-latest, windows-latest]
use-dotnet: [false, true]
include-templates: [false, true]
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
Expand All @@ -50,6 +51,7 @@ jobs:
# Pre-release label is optional.
version: 4.0.0
use-dotnet: ${{ matrix.use-dotnet }}
include-templates: ${{ matrix.include-templates }}

- name: 🔬 Verify Dotnet
if: ${{ matrix.use-dotnet }}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Setup Godot for use with (or without) .NET on macOS, Windows, and Linux CI/CD runners.

- ✅ Installs Godot 4.x
-Installs export templates.
-Optionally installs export templates.
- ✅ C# supported using .NET version of Godot.
- ✅ Versions **without** .NET are also supported.
- ✅ Installs Godot directly on the CI/CD runner.
Expand Down Expand Up @@ -63,6 +63,8 @@ jobs:
version: 4.0.0-beta16 # also valid: 4.0.0.rc1 or 4.0.0, etc
# Use .NET-enabled version of Godot (the default is also true).
use-dotnet: true
# Include the Godot Export Templtes (the default is false).
include-templates: true

- name: 🔬 Verify Setup
run: |
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ inputs:
use-dotnet:
description: >-
True to use the .NET-enabled version of Godot that enables C#, false to use the default version.
default: 'true'
default: true
include-templates:
description: >-
True will also download the Godot Export Templates for each platform.
default: false
runs:
using: 'node16'
main: 'dist/index.js'
69 changes: 39 additions & 30 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.

128 changes: 71 additions & 57 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function run(platform: Platform): Promise<void> {
const binRelativePath = core.getInput('bin-path').replace(/\s/g, '')
const godotSharpRelease = core.getBooleanInput('godot-sharp-release')
const checkoutDirectory = process.env['GITHUB_WORKSPACE'] ?? ''
const includeTemplates = core.getBooleanInput('include-templates')

const userDir = os.homedir()
const downloadsDir = path.join(userDir, downloadsRelativePath)
Expand Down Expand Up @@ -74,12 +75,12 @@ async function run(platform: Platform): Promise<void> {
)
const binDir = path.join(userDir, binRelativePath)

const exportTemplateUrl = getGodotUrl(version, platform, useDotnet, true)
const exportTemplatePath = getExportTemplatePath(version, platform, useDotnet)
const exportTemplateDownloadPath = path.join(
const exportTemplateUrl = includeTemplates ? getGodotUrl(version, platform, useDotnet, true) : ''
const exportTemplatePath = includeTemplates ? getExportTemplatePath(version, platform, useDotnet) : ''
const exportTemplateDownloadPath = includeTemplates ? path.join(
downloadsDir,
'export_templates.zip'
)
) : ''

core.info(`🤖 Godot version: ${version}`)
core.info(`🤖 Godot version name: ${versionName}`)
Expand All @@ -90,9 +91,15 @@ async function run(platform: Platform): Promise<void> {
core.info(`📥 Godot download path: ${godotDownloadPath}`)
core.info(`📦 Godot installation directory: ${installationDir}`)
core.info(`🤖 Godot installation path: ${godotInstallationPath}`)
core.info(`🤖 Export Template url: ${exportTemplateUrl}`)
core.info(`📥 Export Template download path: ${exportTemplateDownloadPath}`)
core.info(`🤖 Export Template Path: ${exportTemplatePath}`)

if (includeTemplates) {
core.info(`🤖 Export Template url: ${exportTemplateUrl}`)
core.info(`📥 Export Template download path: ${exportTemplateDownloadPath}`)
core.info(`🤖 Export Template Path: ${exportTemplatePath}`)
} else {
core.info(`⏭️ Skipping Export Templates.`)
}

core.info(`📂 Bin directory: ${binDir}`)
core.info(`🤖 GodotSharp release: ${godotSharpRelease}`)
core.endGroup()
Expand All @@ -108,9 +115,12 @@ async function run(platform: Platform): Promise<void> {

// See if Godot is already installed.
core.startGroup(`🤔 Checking if Godot is already in cache...`)

const cachedPaths = includeTemplates ? [ godotInstallationPath, exportTemplatePath] : [ godotInstallationPath ]
const cacheKey = includeTemplates ? godotUrl : godotUrl + '-no-templates'
const cached = await cache.restoreCache(
[godotInstallationPath, exportTemplatePath],
godotUrl
cachedPaths.slice(),
cacheKey
)

let executables: string[]
Expand All @@ -131,20 +141,6 @@ async function run(platform: Platform): Promise<void> {
core.info(`✅ Godot downloaded to ${godotDownloadedPath}`)
core.endGroup()

core.startGroup(
`📥 Downloading Export Templates to ${exportTemplateDownloadPath}...`
)

// If the ZIP file already exists locally, delete it before downloading
if (fs.existsSync(exportTemplateDownloadPath))
fs.rmSync(exportTemplateDownloadPath)

const templateDownloadedPath = await toolsCache.downloadTool(
exportTemplateUrl,
exportTemplateDownloadPath
)
core.info(`✅ Export Templates downloaded to ${templateDownloadedPath}`)
core.endGroup()

// Extract Godot
core.startGroup(`📦 Extracting Godot to ${installationDir}...`)
Expand All @@ -170,44 +166,63 @@ async function run(platform: Platform): Promise<void> {
core.info(`✅ Files shown`)
core.endGroup()

core.startGroup(
`📦 Extracting Export Templates to ${exportTemplatePath}...`
)

// If the export template folder already exists, remove it before extracting the ZIP file. This will "uninstall" other installations (e.g. on version changes).
if (fs.existsSync(exportTemplatePath))
fs.rmdirSync(exportTemplatePath, {recursive: true})

const exportTemplateExtractedPath = await toolsCache.extractZip(
templateDownloadedPath,
path.dirname(exportTemplatePath)
)
core.info(
`✅ Export Templates extracted to ${exportTemplateExtractedPath}`
)
fs.renameSync(
path.join(exportTemplateExtractedPath, 'templates'),
exportTemplatePath
)
core.info(
`✅ ${path.join(
path.dirname(exportTemplateExtractedPath),
'templates'
)} moved to ${exportTemplatePath}`
)
core.endGroup()

// Show extracted Export Template files recursively
core.startGroup(`📄 Showing extracted files recursively...`)
await findExecutablesRecursively(platform, exportTemplatePath, '')
core.info(`✅ Files shown`)
core.endGroup()
if (includeTemplates) {
core.startGroup(
`📥 Downloading Export Templates to ${exportTemplateDownloadPath}...`
)

// If the ZIP file already exists locally, delete it before downloading
if (fs.existsSync(exportTemplateDownloadPath))
fs.rmSync(exportTemplateDownloadPath)

const templateDownloadedPath = await toolsCache.downloadTool(
exportTemplateUrl,
exportTemplateDownloadPath
)
core.info(`✅ Export Templates downloaded to ${templateDownloadedPath}`)
core.endGroup()


core.startGroup(
`📦 Extracting Export Templates to ${exportTemplatePath}...`
)

// If the export template folder already exists, remove it before extracting the ZIP file. This will "uninstall" other installations (e.g. on version changes).
if (fs.existsSync(exportTemplatePath))
fs.rmdirSync(exportTemplatePath, {recursive: true})

const exportTemplateExtractedPath = await toolsCache.extractZip(
templateDownloadedPath,
path.dirname(exportTemplatePath)
)
core.info(
`✅ Export Templates extracted to ${exportTemplateExtractedPath}`
)
fs.renameSync(
path.join(exportTemplateExtractedPath, 'templates'),
exportTemplatePath
)
core.info(
`✅ ${path.join(
path.dirname(exportTemplateExtractedPath),
'templates'
)} moved to ${exportTemplatePath}`
)
core.endGroup()

// Show extracted Export Template files recursively
core.startGroup(`📄 Showing extracted files recursively...`)
await findExecutablesRecursively(platform, exportTemplatePath, '')
core.info(`✅ Files shown`)
core.endGroup()
}

// Save extracted Godot contents to cache
core.startGroup(`💾 Saving extracted Godot download to cache...`)
await cache.saveCache(
[godotInstallationPath, exportTemplatePath],
godotUrl
cachedPaths,
cacheKey
)
core.info(`✅ Godot saved to cache`)
core.endGroup()
Expand All @@ -221,7 +236,6 @@ async function run(platform: Platform): Promise<void> {
installationDir,
''
)
await findExecutablesRecursively(platform, exportTemplatePath, '')
core.info(`✅ Files shown`)
core.endGroup()
}
Expand Down

0 comments on commit 1dc3741

Please sign in to comment.