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

chore: adds dogfood workflow for building/release CLI binary #34

Merged
merged 63 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6facc02
test: adds initial dogfood test for actions
jmgilman Oct 9, 2023
b30753f
wip: uses build target
jmgilman Oct 9, 2023
b716de5
wip: adds platform
jmgilman Oct 9, 2023
2497b57
feat: adds artifact_output input to run action
jmgilman Oct 9, 2023
84ee9d4
wip: tests uploading artifacts
jmgilman Oct 9, 2023
8eb9bd6
fix: checks for artifact_output
jmgilman Oct 9, 2023
a3741d0
wip: removes binary and simplifies artifact saving
jmgilman Oct 9, 2023
bfead61
fix: positions artifact arguments correctly
jmgilman Oct 9, 2023
a21c469
fix: uses correct artifact path
jmgilman Oct 9, 2023
0a57a9b
fix: cleans up earthfile name
jmgilman Oct 10, 2023
55988df
wip: test
jmgilman Oct 10, 2023
939b8eb
wip: testing
jmgilman Oct 10, 2023
b2afa24
wip: testing
jmgilman Oct 10, 2023
20bb033
wip: testing
jmgilman Oct 10, 2023
a4c3096
wip: testing
jmgilman Oct 10, 2023
e9c0c90
wip: simplify artifact name
jmgilman Oct 10, 2023
188a61d
wip: tests downloading artifacts
jmgilman Oct 10, 2023
be2aa03
refactor: simplifies artifact extraction to a single artifact
jmgilman Oct 10, 2023
3dac6f8
wip: fixes inputs
jmgilman Oct 10, 2023
d21f77f
refactor: simplify image extraction to a single image
jmgilman Oct 10, 2023
74e21d7
feat: adds platform input
jmgilman Oct 10, 2023
527ed64
wip: uses new platform input
jmgilman Oct 10, 2023
cfe0e22
wip: compresses artifact
jmgilman Oct 10, 2023
c7f767a
wip: removes recursion with tar
jmgilman Oct 10, 2023
e73a7f3
wip: testing
jmgilman Oct 10, 2023
386433b
wip: removes test code
jmgilman Oct 10, 2023
532986d
wip: fixes compression
jmgilman Oct 10, 2023
8869b9f
wip: testing
jmgilman Oct 10, 2023
43d294b
wip: creates release
jmgilman Oct 10, 2023
23ff65a
refactor: moves to reusable workflow
jmgilman Oct 10, 2023
cdea208
fix: don't use env
jmgilman Oct 10, 2023
fa176c4
chore: adds release target to cli
jmgilman Oct 10, 2023
c9f9055
wip: test no targets
jmgilman Oct 10, 2023
8b56b08
fix: fixes typo/formatting
jmgilman Oct 10, 2023
fcc5cf2
fix: output `[]` when no targets are found
jmgilman Oct 10, 2023
343af40
wip: testing
jmgilman Oct 10, 2023
840375f
wip: testing
jmgilman Oct 10, 2023
8ba693e
wip: testing
jmgilman Oct 10, 2023
ab9086b
wip: testing
jmgilman Oct 10, 2023
10ac487
wip: testing
jmgilman Oct 10, 2023
8884103
wip: testing
jmgilman Oct 10, 2023
14eba1e
wip: testing
jmgilman Oct 10, 2023
c659986
wip: testing
jmgilman Oct 10, 2023
7935648
wip: testing
jmgilman Oct 10, 2023
125edaa
wip: testing
jmgilman Oct 10, 2023
340af73
wip: testing
jmgilman Oct 10, 2023
a19e014
wip: testing
jmgilman Oct 10, 2023
80116fb
wip: testing
jmgilman Oct 10, 2023
825aefa
wip: testing
jmgilman Oct 10, 2023
40f6d58
wip: testing
jmgilman Oct 10, 2023
ac076f6
wip: testing
jmgilman Oct 10, 2023
c15cf2c
wip: testing
jmgilman Oct 10, 2023
8d60c70
wip: cleanup
jmgilman Oct 10, 2023
e429c27
fix: don't upload artifacts by default
jmgilman Oct 10, 2023
6e96241
wip: testing
jmgilman Oct 10, 2023
4f89b7d
wip: testing
jmgilman Oct 10, 2023
23f4208
wip: testing
jmgilman Oct 11, 2023
e26a860
refactor: don't upload artifacts on PR pushes
jmgilman Oct 11, 2023
261bd53
wip: testing
jmgilman Oct 11, 2023
c0d0820
wip: return to previous
jmgilman Oct 11, 2023
86b6127
wip: testing
jmgilman Oct 11, 2023
00257bf
wip: cleanup
jmgilman Oct 11, 2023
29d5fa6
chore: points back to master branch
jmgilman Oct 11, 2023
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
29 changes: 8 additions & 21 deletions .github/workflows/dogfood.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@ permissions:
contents: read
packages: write

env:
AWS_REGION: eu-central-1
AWS_ROLE_ARN: arn:aws:iam::332405224602:role/ci
EARTHLY_VERSION: 0.7.15

jobs:
dogfood:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: input-output-hk/catalyst-ci/actions/setup@actions-2.0
with:
aws_role_arn: ${{ env.AWS_ROLE_ARN }}
aws_region: ${{ env.AWS_REGION }}
earthly_version: ${{ env.EARTHLY_VERSION }}
- uses: input-output-hk/catalyst-ci/actions/run@actions-2.0
with:
earthfile: ./cli
target: build
runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }}
- name: Test
run: ./cli/bin/ci --help
release:
uses: ./.github/workflows/release.yml
with:
aws_role_arn: arn:aws:iam::332405224602:role/ci
aws_region: eu-central-1
earthly_version: 0.7.15
secrets:
earthly_runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }}
133 changes: 133 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
on:
workflow_call:
inputs:
target:
description: |
The target used to mark release builds. This target should be unique
across all Earthly files in the repository. The target should always
produce at least one artifact which is included in the final GitHub
release when the workflow is triggered by a tag.
required: false
type: string
default: release
aws_role_arn:
description: |
The ARN of the AWS role that will be assumed by the workflow. Only
required when configuring a remote Earthly runner.
required: false
type: string
aws_region:
description: |
The AWS region that will be used by the workflow. Only required when
configuring a remote Earthly runner.
required: false
type: string
earthly_version:
description: The version of Earthly to use.
required: false
type: string
default: latest
force_artifact:
description: |
When set to true, the workflow will always produce an artifact even
when the current commit is not tagged.
required: false
type: boolean
default: false
secrets:
earthly_runner_address:
description: |
The address of the Earthly runner that will be used to build the
Earthly files.
required: false

jobs:
discover:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.check.outputs.json }}
steps:
- uses: actions/checkout@v3
- name: Setup CI
uses: input-output-hk/catalyst-ci/actions/setup@master
with:
aws_role_arn: ${{ inputs.aws_role_arn }}
aws_region: ${{ inputs.aws_region }}
earthly_version: ${{ inputs.earthly_version }}
- name: Discover Earthly files
uses: input-output-hk/catalyst-ci/actions/discover@master
id: discover
with:
targets: ${{ inputs.target }}
- name: Check for empty output
id: check
run: |
output=$(echo '${{ steps.discover.outputs.json }}' | jq -rc)
if [ "$output" == "null" ]; then
echo "json=[]" >> $GITHUB_OUTPUT
else
echo "json=$output" >> $GITHUB_OUTPUT
fi

build:
runs-on: ubuntu-latest
needs: [discover]
if: needs.discover.outputs.json != '[]'
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
earthfile: ${{ fromJson(needs.discover.outputs.json) }}
steps:
- uses: actions/checkout@v3
- name: Setup CI
uses: input-output-hk/catalyst-ci/actions/setup@master
with:
aws_role_arn: ${{ inputs.aws_role_arn }}
aws_region: ${{ inputs.aws_region }}
earthly_version: ${{ inputs.earthly_version }}
- name: Build artifact
uses: input-output-hk/catalyst-ci/actions/run@master
id: build
with:
earthfile: ${{ matrix.earthfile }}
target: ${{ inputs.target }}
platform: ${{ matrix.platform }}
runner_address: ${{ secrets.earthly_runner_address }}
artifact: "true"
- name: Generate artifact name
if: startsWith(github.ref, 'refs/tags/') || inputs.force_artifact
id: artifact
run: |
earthfile=$(basename ${{ matrix.earthfile }})
platform=$(echo '${{ matrix.platform }}' | sed 's/\//-/g')
echo "name=$earthfile-$platform" >> $GITHUB_OUTPUT
- name: Compress artifact
if: startsWith(github.ref, 'refs/tags/') || inputs.force_artifact
run: |
cwd=$(pwd)
cd ${{ steps.build.outputs.artifact }} && tar -czvf "$cwd/${{ steps.artifact.outputs.name }}.tar.gz" .
- name: Upload artifact
uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/') || inputs.force_artifact
with:
name: ${{ steps.artifact.outputs.name }}
path: ${{ steps.artifact.outputs.name }}.tar.gz

release:
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Collect artifacts
id: collect
run: echo "artifacts=$(find artifacts -type f -name '*.tar.gz')" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@v1
with:
files: ${{ steps.collect.outputs.artifacts }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
.direnv
.envrc.local

# Earthly
bin/

# Node
node_modules

Expand Down
10 changes: 9 additions & 1 deletion actions/run/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ name: "Run"
description: "Runs an Earthly target"
inputs:
artifact:
description: The name of the artifact to export
description: If true, forces artifacts to be saved locally
required: false
default: "false"
artifact_path:
description: The path (relative to earthfile) where artifacts will be placed
required: false
default: out
earthfile:
description: The path to the Earthfile containing the target to run
required: true
flags:
description: Additional flags to pass to the Earthly CLI
required: false
platform:
description: The platform to execute the earthfile target with (defaults to native)
required: false
runner_address:
description: The address of the remote runner to use
required: false
Expand Down
60 changes: 39 additions & 21 deletions actions/run/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2870,52 +2870,70 @@ __nccwpck_require__.r(__webpack_exports__);
var core = __nccwpck_require__(186);
;// CONCATENATED MODULE: external "child_process"
const external_child_process_namespaceObject = require("child_process");
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(17);
;// CONCATENATED MODULE: ./src/run.ts



async function run() {
const artifact = core.getInput('artifact');
const artifact = core.getBooleanInput('artifact');
const artifactPath = core.getInput('artifact_path');
const earthfile = core.getInput('earthfile');
const flags = core.getInput('flags');
const platform = core.getInput('platform');
const runnerAddress = core.getInput('runner_address');
const runnerPort = core.getInput('runner_port');
const target = core.getInput('target');
const targetFlags = core.getInput('target_flags');
const command = 'earthly';
const args = [];
if (artifact) {
args.push('--artifact', `${earthfile}+${target}/${artifact}`, `${artifact}`);
}
if (runnerAddress) {
args.push('--buildkit-host', `tcp://${runnerAddress}:${runnerPort}`);
}
if (platform) {
args.push('--platform', platform);
}
if (flags) {
args.push(...flags.split(' '));
}
if (!artifact) {
if (artifact) {
args.push('--artifact', `${earthfile}+${target}/`, `${artifactPath}`);
}
else {
args.push(`${earthfile}+${target}`);
}
if (targetFlags) {
args.push(...targetFlags.split(' '));
}
core.info(`Running command: ${command} ${args.join(' ')}`);
const output = await spawnCommand(command, args);
// TODO: The newest version of Earthly attaches annotations to the images
let matches;
const imageRegex = /^Image .*? output as (.*?)$/gm;
const images = [];
while ((matches = imageRegex.exec(output)) !== null) {
images.push(matches[1]);
}
const artifactRegex = /^Artifact .*? output as (.*?)$/gm;
const artifacts = [];
while ((matches = artifactRegex.exec(output)) !== null) {
artifacts.push(matches[1]);
}
core.info(`Found images: ${images.join(' ')}`);
core.info(`Found artifacts: ${artifacts.join(' ')}`);
core.setOutput('images', images.join(' '));
core.setOutput('artifacts', artifacts.join(' '));
const imageOutput = parseImage(output);
if (imageOutput) {
core.info(`Found image: ${imageOutput}`);
core.setOutput('image', imageOutput);
}
const artifactOutput = external_path_.join(earthfile, parseArtifact(output));
if (artifactOutput !== earthfile) {
core.info(`Found artifact: ${artifactOutput}`);
core.setOutput('artifact', artifactOutput);
}
}
function parseArtifact(output) {
const regex = /^Artifact .*? output as (.*?)$/gm;
const match = regex.exec(output);
if (match) {
return match[1];
}
return '';
}
function parseImage(output) {
const regex = /^Image .*? output as (.*?)$/gm;
const match = regex.exec(output);
if (match) {
return match[1];
}
return '';
}
async function spawnCommand(command, args) {
return new Promise((resolve, reject) => {
Expand Down
Loading
Loading