Skip to content

Commit

Permalink
Support installing different TeX Live releases
Browse files Browse the repository at this point in the history
  • Loading branch information
zauguin committed Feb 23, 2025
1 parent 320fc78 commit 2979de7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
with:
packages: latex-bin
cache_version: ${{ github.run_id }}_${{ github.run_attempt }}
texlive_version: '2024'
- run: pdflatex test.tex

run-with-cache:
Expand All @@ -85,6 +86,7 @@ jobs:
packages: latex-bin
cache_version: ${{ github.run_id }}_${{ github.run_attempt }}
repository: https://127.0.0.42/not-a-texlive-mirror/
texlive_version: '2024'
- run: pdflatex test.tex
- name: '"pdflatex test-enumitem.tex" should fail'
run: |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ branding:
color: blue

inputs:
texlive_version:
description: 'The TeX Live version to install'
required: false
repository:
description: 'The repository to install TeX Live from'
required: false
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 30 additions & 9 deletions dist/index.js

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

65 changes: 54 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as os from 'node:os'
import { getProfile } from './tlprofile.js'

interface AliveMirror {
status: 'Alive'
status: 'Alive' | 'Special'
texlive_version: number
revision: number
}
Expand All @@ -36,6 +36,12 @@ function getOptionalInput(name: string): string | undefined {
return core.getInput(name) || undefined
}

function getOptionalNumberInput(name: string): number | undefined {
const input = getOptionalInput(name)
if (input === undefined) return undefined
return parseInt(input)
}

async function inlineOrFilecontent(
inline: string | undefined,
filename: string | undefined
Expand All @@ -57,7 +63,9 @@ export function parsePackages(packagesString: string): string[] {

async function calculateCacheKey(
version: string,
packages: string[]
packages: string[],
texlive_version: number | undefined,
revision: number | undefined
): Promise<{
prefix: string
full: string
Expand All @@ -73,8 +81,9 @@ async function calculateCacheKey(
.map(byte => byte.toString(16).padStart(2, '0'))
.join('')
const osid = `${os.platform()}-${os.machine()}`
const cachePrefix = `texlive-${osid}-${version}-${packageHash}-`
const cacheKey = cachePrefix + Temporal.Now.plainDateISO('UTC').toString()
const cachePrefix = `texlive-${osid}-${version}-${packageHash}-${texlive_version || 'NONE'}-`
const cacheKey =
cachePrefix + (revision ?? Temporal.Now.plainDateISO('UTC').toString())
return {
prefix: cachePrefix,
full: cacheKey
Expand Down Expand Up @@ -109,7 +118,22 @@ function detectTlPlatform(): TlPlatform {
}
}

async function findRepository(): Promise<string | undefined> {
function mirrorIsApplicable(
mirrorData: MirrorData,
version: number | undefined
): boolean {
if (version === undefined) {
return mirrorData.status === 'Alive'
}
if (!(mirrorData.status === 'Alive' || mirrorData.status === 'Special')) {
return false
}
return mirrorData.texlive_version === version
}

async function findRepository(
version: number | undefined
): Promise<[string, number, number] | undefined> {
const http = new HttpClient()
let mirrorList: MirrorList | undefined
try {
Expand All @@ -131,7 +155,7 @@ async function findRepository(): Promise<string | undefined> {
return undefined
}
const usMirrors = Object.entries(mirrorList['North America'].USA).filter(
([_, { status }]) => status === 'Alive'
([_, data]) => mirrorIsApplicable(data, version)
) as [string, AliveMirror][]
if (usMirrors.length === 0) {
throw new Error('No mirror available')
Expand All @@ -153,7 +177,7 @@ async function findRepository(): Promise<string | undefined> {
core.info(
`Selected mirror ${mirror} (TeX Live ${highestVersion}, rev. ${highestRevision})`
)
return mirror
return [mirror, highestVersion, highestRevision]
}

function handleExecResult(description: string, status: number): void {
Expand Down Expand Up @@ -230,10 +254,24 @@ async function installTexLive(
)
}

async function resolveRepository(
texlive_version: number | undefined,
requested_repository: string | undefined
): Promise<[string | undefined, number | undefined, number | undefined]> {
if (requested_repository !== undefined) {
return [requested_repository, texlive_version, undefined]
}
return (
(await findRepository(texlive_version)) || [undefined, undefined, undefined]
)
}

export async function run(): Promise<void> {
try {
const repository =
getOptionalInput('repository') ?? (await findRepository())
const [repository, texlive_version, revision] = await resolveRepository(
getOptionalNumberInput('texlive_version'),
getOptionalInput('repository')
)
const packageFile = getOptionalInput('package_file')
const packagesInline = getOptionalInput('packages')
const cacheVersion = getMandatoryInput('cache_version')
Expand All @@ -250,7 +288,12 @@ export async function run(): Promise<void> {
return parsePackages(packageString)
})()

const cacheKey = await calculateCacheKey(cacheVersion, packages)
const cacheKey = await calculateCacheKey(
cacheVersion,
packages,
texlive_version,
revision
)

const home = os.homedir()
const tlPlatform = detectTlPlatform()
Expand All @@ -268,7 +311,7 @@ export async function run(): Promise<void> {
return
}

// Installing TeX Live gets another try clock to handle acceptStale
// Installing TeX Live gets another try block to handle acceptStale
try {
await installTexLive(
restoredCache === undefined,
Expand Down

0 comments on commit 2979de7

Please sign in to comment.