Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example workflows #69

Merged
merged 6 commits into from
Sep 19, 2023
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"distclean",
"dockerfile",
"dockerfiles",
"dooper",
"dotconfig",
"edkii",
"exitcode",
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indent_style = tab
indent_style = space
indent_size = 4

[*.{json,yml,yaml,js}]
[*.{json,yml,yaml,js,mjs}]
indent_style = space
indent_size = 2

Expand Down
119 changes: 119 additions & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
# Example of using firmware-action

name: example
on:
pull_request:
merge_group:
push:

# branches:
# - main

env:
APPLY_FIXES: none
APPLY_FIXES_EVENT: pull_request
APPLY_FIXES_MODE: commit
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

permissions:
contents: read

jobs:
# Example of building coreboot
build-coreboot:
runs-on: ubuntu-latest
strategy:
matrix:
coreboot-version: ['4.19', '4.20.1', '4.21']
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Clone coreboot repo
run: |
git clone --branch "${{ matrix.coreboot-version }}" --depth 1 https://review.coreboot.org/coreboot my_super_dooper_awesome_coreboot
- name: Move my defconfig into place (filename must not contain '.defconfig')
run: |
mv "tests/coreboot_${{ matrix.coreboot-version }}/seabios.defconfig" "seabios_defconfig"
- name: firmware-action
uses: ./
#uses: 9elements/firmware-action
with:
target: coreboot
sdk_version: 'coreboot_${{ matrix.coreboot-version }}:main'
#architecture: x86 # default
repo_path: my_super_dooper_awesome_coreboot
defconfig_path: 'seabios_defconfig'
#output: "output" # default

# Example of building Linux kernel
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
linux-version: [6.1.45]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prepare linux kernel
run: |
# Download source files
wget --quiet "https://cdn.kernel.org/pub/linux/kernel/v${LINUX_MAJOR_VERSION}.x/linux-${{ matrix.linux-version }}.tar.xz"
wget --quiet "https://cdn.kernel.org/pub/linux/kernel/v${LINUX_MAJOR_VERSION}.x/linux-${{ matrix.linux-version }}.tar.sign"
unxz "linux-${{ matrix.linux-version }}.tar.xz" >/dev/null
# Verify GPG signature
gpg2 --locate-keys torvalds@kernel.org gregkh@kernel.org
gpg2 --verify "linux-${{ matrix.linux-version }}.tar.sign"
# Extract
tar -xvf "linux-${{ matrix.linux-version }}.tar"
env:
LINUX_MAJOR_VERSION: 6
- name: Move my defconfig into place (filename must not contain '.defconfig')
run: |
mv "tests/linux_${{ matrix.linux-version }}/linux.defconfig" "ci_defconfig"
- name: firmware-action
uses: ./
#uses: 9elements/firmware-action
with:
target: linux
sdk_version: 'linux_${{ matrix.linux-version }}:main'
#architecture: x86 # default
repo_path: 'linux-${{ matrix.linux-version }}'
defconfig_path: 'ci_defconfig'
#output: "output" # default

# Example of building EDK2
build-edk2:
runs-on: ubuntu-latest
strategy:
matrix:
edk2-version: ['edk2-stable202208', 'edk2-stable202211']
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Clone edk2 repo
run: |
git clone --recurse-submodules --branch "${{ matrix.edk2-version }}" --depth 1 https://github.com/tianocore/edk2.git Edk2
- name: Prepare file with build arguments
run: |
echo "-t GCC5 -D BOOTLOADER=COREBOOT -D TPM_ENABLE=TRUE -D NETWORK_IPXE=TRUE" > "edk2_config.cfg"
- name: firmware-action
uses: ./
#uses: 9elements/firmware-action
with:
target: edk2
sdk_version: '${{ matrix.edk2-version }}:main'
architecture: X64
repo_path: 'Edk2'
defconfig_path: 'edk2_config.cfg'
#output: "output" # default
edk2__platform: 'UefiPayloadPkg/UefiPayloadPkg.dsc'
#edk2__release_type: DEBUG # default
9 changes: 6 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ inputs:
description: |
*architecture* specifies target architecture, such as 'x86' or 'arm64'.
required: true
default: 'x86'
repo_path:
description: |
*repo_path* gives the (relative) path to the target (firmware) repository.
If the current repository contains the selected target, specify: '.'
Otherwise the path should point to the target (firmware) repository
submodule that had previously been checked out.
required: true
default: '.'
defconfig_path:
description: |
*defconfig_path* gives the (relative to repo_path) path to the defconfig that
*defconfig_path* gives the (relative) path to the defconfig that
should be used to build the target.
For coreboot and linux this is a defconfig.
For EDK2 this is a one-line file containing the build arguments
Expand All @@ -55,8 +57,9 @@ inputs:
required: true
output:
description: |
*output* specifies the (relative) path where to place the produced files
*output* specifies the (relative) path to directory into which place the produced files
required: true
default: 'output'

#-------------------------------
# Inputs specific for coreboot target
Expand Down Expand Up @@ -143,4 +146,4 @@ inputs:

runs:
using: 'node16'
AtomicFS marked this conversation as resolved.
Show resolved Hide resolved
main: 'dist/invoke-action.js'
main: 'dist/invoke-action.mjs'
8 changes: 8 additions & 0 deletions action/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"os"
"path/filepath"

"dagger.io/dagger"
Expand Down Expand Up @@ -90,6 +91,7 @@ type Artifacts struct {
ContainerPath string // Path inside container
ContainerDir bool // Is ^^^ path directory?
HostPath string // Path inside host
HostDir bool // Is ^^^ path directory?
}

// GetArtifacts extracts files from container to host
Expand All @@ -104,6 +106,12 @@ func GetArtifacts(ctx context.Context, container *dagger.Container, artifacts *[
var success bool
var err error

if artifact.HostDir {
if err := os.MkdirAll(artifact.HostPath, 0o755); err != nil {
return err
}
}

// Export
// If allowParentDirPath is true, the path argument can be a directory path, in which case
// the file will be created in that directory.
Expand Down
7 changes: 7 additions & 0 deletions action/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: "",
ContainerDir: true,
HostPath: tmpDir,
HostDir: true,
}},
wantErrExport: errDirectoryNotSpecified,
filepathToTest: []string{filename},
Expand All @@ -168,6 +169,7 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: "/src",
ContainerDir: true,
HostPath: tmpDir,
HostDir: true,
}},
wantErrExport: nil,
filepathToTest: []string{filepath.Join("/src", filename)},
Expand All @@ -180,6 +182,7 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: filepath.Join("/src", filename),
ContainerDir: false,
HostPath: filepath.Join(tmpDir, filename),
HostDir: false,
}},
wantErrExport: nil,
filepathToTest: []string{filename},
Expand All @@ -197,11 +200,13 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: filepath.Join("/src", filename),
ContainerDir: false,
HostPath: tmpDir,
HostDir: true,
},
{
ContainerPath: filepath.Join("/src", filename2),
ContainerDir: false,
HostPath: tmpDir,
HostDir: true,
},
},
wantErrExport: nil,
Expand All @@ -218,6 +223,7 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: "/src",
ContainerDir: true,
HostPath: tmpDir,
HostDir: true,
}},
wantErrExport: nil,
filepathToTest: []string{filepath.Join("/src", prefix, filename)},
Expand All @@ -230,6 +236,7 @@ func TestGetArtifacts(t *testing.T) {
ContainerPath: "/some/non-existing/directory/path",
ContainerDir: true,
HostPath: tmpDir,
HostDir: true,
}},
wantErrExport: errExportFailed,
filepathToTest: []string{filepath.Join(prefix, filename)},
Expand Down
11 changes: 5 additions & 6 deletions action/recipes/coreboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func TestCoreboot(t *testing.T) {
"sdk_version": fmt.Sprintf("coreboot_%s:main", corebootVersion),
"architecture": "x86",
"repo_path": filepath.Join(tmpDir, "coreboot"),
"defconfig_path": "defconfig",
"defconfig_path": "seabios_defconfig",
"containerWorkDir": "/coreboot",
"GITHUB_WORKSPACE": "/coreboot",
"output": "output",
}
getFunc := func(key string) string {
return opts[key]
}
common, err := commonGetOpts(getFunc)
common, err := commonGetOpts(getFunc, getFunc)
assert.NoError(t, err)
corebootOpts := corebootOpts{}

Expand All @@ -59,18 +59,15 @@ func TestCoreboot(t *testing.T) {
cmd := exec.Command("git", "clone", "--branch", corebootVersion, "--depth", "1", "https://review.coreboot.org/coreboot")
err = cmd.Run()
assert.NoError(t, err)
err = os.Chdir(common.repoPath)
assert.NoError(t, err)

// Copy over defconfig file into tmpDir
defconfigPath := filepath.Join(common.repoPath, "defconfig")
repoRootPath, err := filepath.Abs(filepath.Join(pwd, "../.."))
assert.NoError(t, err)
// common.repoPath = path to end user repository (in this case somewhere in /tmp)
// repoRootPath = path to our repository with this code (contains configuration files for testing)
err = filesystem.CopyFile(
filepath.Join(repoRootPath, fmt.Sprintf("tests/coreboot_%s/seabios.defconfig", corebootVersion)),
defconfigPath,
filepath.Join(tmpDir, common.defconfigPath),
)
assert.NoError(t, err)

Expand All @@ -83,11 +80,13 @@ func TestCoreboot(t *testing.T) {
ContainerPath: filepath.Join(common.containerWorkDir, "build", "coreboot.rom"),
ContainerDir: false,
HostPath: outputPath,
HostDir: true,
},
{
ContainerPath: filepath.Join(common.containerWorkDir, "defconfig"),
ContainerDir: false,
HostPath: outputPath,
HostDir: true,
},
}

Expand Down
3 changes: 2 additions & 1 deletion action/recipes/edk2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestEdk2(t *testing.T) {
getFunc := func(key string) string {
return opts[key]
}
common, err := commonGetOpts(getFunc)
common, err := commonGetOpts(getFunc, getFunc)
assert.NoError(t, err)
edk2Opts := edk2Opts{
platform: tc.platform,
Expand Down Expand Up @@ -105,6 +105,7 @@ func TestEdk2(t *testing.T) {
ContainerPath: filepath.Join(common.containerWorkDir, "Build"),
ContainerDir: true,
HostPath: outputPath,
HostDir: true,
},
}

Expand Down
4 changes: 3 additions & 1 deletion action/recipes/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestLinux(t *testing.T) {
getFunc := func(key string) string {
return opts[key]
}
common, err := commonGetOpts(getFunc)
common, err := commonGetOpts(getFunc, getFunc)
assert.NoError(t, err)
linuxOpts := linuxOpts{}

Expand Down Expand Up @@ -154,11 +154,13 @@ func TestLinux(t *testing.T) {
ContainerPath: filepath.Join(common.containerWorkDir, "vmlinux"),
ContainerDir: false,
HostPath: outputPath,
HostDir: true,
},
{
ContainerPath: filepath.Join(common.containerWorkDir, "defconfig"),
ContainerDir: false,
HostPath: outputPath,
HostDir: true,
},
}

Expand Down
Loading