Skip to content

Commit

Permalink
Add caching of pi-gen artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
usimd committed Feb 25, 2024
1 parent 37492e5 commit 0d449b0
Show file tree
Hide file tree
Showing 11 changed files with 1,535 additions and 68 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
wpa-essid: foo
wpa-password: '1234567890'
timezone: ${{ env.CONFIG_TIMEZONE }}
enable-pigen-cache: true

- name: List working directory
run: tree
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
include: |-
dist/licenses.txt
dist/index.js
dist/pre.js
dist/post.js
README.md
LICENSE
action.yml
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ tries to make sure the stage is respected and its changes are included in the fi
# 'image-noobs-path'.
enable-noobs: false

# Enables caching of pi-gen work artifacts to GitHub action cache to speed up
# repetitive builds.
enable-pigen-cache: false

# Enable SSH access to Pi.
enable-ssh: 0

Expand Down
24 changes: 16 additions & 8 deletions __test__/pi-gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const mockPiGenDependencies = (
])

jest.spyOn(fs, 'realpathSync').mockImplementationOnce(p => `/${p.toString()}`)

jest.spyOn(fs, 'mkdirSync').mockReturnValueOnce('')
}

describe('PiGen', () => {
Expand Down Expand Up @@ -89,6 +91,7 @@ describe('PiGen', () => {
.spyOn(fs, 'realpathSync')
.mockReturnValueOnce('/any/stage/path')
.mockReturnValueOnce('/pi-gen/stage0')
.mockReturnValueOnce('/pigen-work')

const piGen = await PiGen.getInstance(piGenDir, {
stageList: ['/any/stage/path', '/pi-gen/stage0'],
Expand All @@ -102,8 +105,9 @@ describe('PiGen', () => {
expect.objectContaining({
cwd: piGenDir,
env: expect.objectContaining({
PIGEN_DOCKER_OPTS:
'-v /any/stage/path:/any/stage/path -v /pi-gen/stage0:/pi-gen/stage0 -e DEBIAN_FRONTEND=noninteractive'
PIGEN_DOCKER_OPTS: expect.stringContaining(
'-v /any/stage/path:/any/stage/path -v /pi-gen/stage0:/pi-gen/stage0'
)
})
})
)
Expand All @@ -112,7 +116,10 @@ describe('PiGen', () => {
it('passes custom docker opts', async () => {
const piGenDir = 'pi-gen'
mockPiGenDependencies()
jest.spyOn(fs, 'realpathSync').mockReturnValueOnce('/pi-gen/stage0')
jest
.spyOn(fs, 'realpathSync')
.mockReturnValueOnce('/pi-gen/stage0')
.mockReturnValueOnce('/pigen-work')

const piGen = await PiGen.getInstance(piGenDir, {
stageList: ['/pi-gen/stage0'],
Expand All @@ -126,8 +133,9 @@ describe('PiGen', () => {
expect.objectContaining({
cwd: piGenDir,
env: expect.objectContaining({
PIGEN_DOCKER_OPTS:
'-v /foo:/bar -v /pi-gen/stage0:/pi-gen/stage0 -e DEBIAN_FRONTEND=noninteractive'
PIGEN_DOCKER_OPTS: expect.stringContaining(
'-v /foo:/bar -v /pi-gen/stage0:/pi-gen/stage0'
)
})
})
)
Expand Down Expand Up @@ -156,13 +164,13 @@ describe('PiGen', () => {
})

it('configures NOOBS export for stages that export images', async () => {
const stageList = [tmp.dirSync().name, tmp.dirSync().name]
fs.writeFileSync(`${stageList[0]}/EXPORT_IMAGE`, '')

const piGenDir = 'pi-gen'
mockPiGenDependencies()
jest.spyOn(fs, 'realpathSync').mockReturnValueOnce('/pi-gen/stage0')

const stageList = [tmp.dirSync().name, tmp.dirSync().name]
fs.writeFileSync(`${stageList[0]}/EXPORT_IMAGE`, '')

await PiGen.getInstance(piGenDir, {
stageList: stageList,
enableNoobs: 'true'
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ inputs:
If your custom stage requires additional software or kernel modules to be loaded, add them here. Note that this is not meant to configure modules to be loaded in the target image.
required: false
default: ''
enable-pigen-cache:
description: Enables caching of pi-gen work artifacts to GitHub action cache to speed up repetitive builds.
required: false
default: false
pi-gen-dir:
description: Path where selected pi-gen ref will be checked out to. If the path does not yet exist, it will be created (including its parents).
required: false
Expand All @@ -151,8 +155,9 @@ outputs:

runs:
using: node20
pre: dist/pre.js
main: dist/index.js
post: dist/index.js
post: dist/post.js

branding:
icon: box
Expand Down
Loading

0 comments on commit 0d449b0

Please sign in to comment.