Skip to content

Commit

Permalink
feat: adds publish action
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Sep 3, 2024
1 parent 5e6d7ea commit aec5da8
Show file tree
Hide file tree
Showing 21 changed files with 13,483 additions and 38 deletions.
41 changes: 25 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ jobs:
^build.*
^check.*
^test.*
^publish.*
check:
uses: ./.github/workflows/run.yml
needs: [discover]
with:
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^check.*']) }}
forge_version: ${{ inputs.forge_version }}
# check:
# uses: ./.github/workflows/run.yml
# needs: [discover]
# with:
# earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^check.*']) }}
# forge_version: ${{ inputs.forge_version }}

build:
uses: ./.github/workflows/run.yml
needs: [discover, check]
with:
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^build.*']) }}
forge_version: ${{ inputs.forge_version }}
# build:
# uses: ./.github/workflows/run.yml
# needs: [discover, check]
# with:
# earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^build.*']) }}
# forge_version: ${{ inputs.forge_version }}

test:
uses: ./.github/workflows/run.yml
needs: [discover, check, build]
# test:
# uses: ./.github/workflows/run.yml
# needs: [discover, check, build]
# with:
# earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^test.*']) }}
# forge_version: ${{ inputs.forge_version }}

publish:
uses: ./.github/workflows/publish.yml
#needs: [discover, check, build, test]
needs: [discover]
with:
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^test.*']) }}
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['^publish.*']) }}
forge_version: ${{ inputs.forge_version }}
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
workflow_call:
inputs:
earthfiles:
description: |
A JSON list of Earthfile paths+targets to use for publishing
required: true
type: string
forge_version:
description: |
The version of the forge CLI to install (use 'local' for testing)
required: true
type: string

jobs:
run:
name: ${{ matrix.earthfile }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
earthfile: ${{ fromJson(inputs.earthfiles) }}
steps:
- uses: actions/checkout@v4
- name: Setup CI
uses: ./forge/actions/setup
with:
forge_version: ${{ inputs.forge_version }}
- name: Run
id: run
uses: ./forge/actions/run
with:
path: ${{ matrix.earthfile }}
- name: Get image
id: image
run: |
INPUT="${{ matrix.earthfile }}"
EARTHFILE="${INPUT%+*}"
TARGET="${INPUT#*+}"
echo "EARTHFILE: $EARTHFILE"
echo "TARGET: $TARGET"
$RESULT="${{ steps.run.outputs.result }}"
$IMAGE=$(echo "$RESULT" | jq -r ".images[\"$TARGET\"]")
if [[ "$IMAGE" == "null" ]]; then
echo "::error file=${EARTHFILE}/Earthfile::No images produced. Cannot publish."
exit 1
fi
echo "image=$IMAGE" >> $GITHUB_OUTPUT
- name: Show image
run: echo "${{ steps.image.outputs.image }}"
1 change: 1 addition & 0 deletions blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ global: {

github: registry: "ghcr.io"
}
tagging: strategy: "commit"
}
}
29 changes: 21 additions & 8 deletions blueprint/schema/_embed/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ package schema
// Project contains the configuration for the project.
#Project: {
// Name contains the name of the project.
name: string @go(Name)
name: =~"^[a-z][a-z0-9_-]*$" @go(Name)

// Container is the name that the container will be built as.
container: (_ | *name) & {
string
} @go(Container)

// CI contains the configuration for the CI system.
// +optional
ci?: #ProjectCI @go(CI)
}
#ProjectCI: {
// Targets configures the individual targets that are run by the CI system.
// +optional
targets?: {
[string]: #Target
} @go(Targets,map[string]Target)
}

// CI contains the configuration for the CI system.
#GlobalCI: {
Expand All @@ -47,6 +45,17 @@ package schema
// Registries contains the container registries to push images to.
// +optional
registries?: [...string] @go(Registries,[]string)

// Tagging contains the tagging configuration for the CI system.
// +optional
tagging?: #Tagging @go(Tagging)
}
#ProjectCI: {
// Targets configures the individual targets that are run by the CI system.
// +optional
targets?: {
[string]: #Target
} @go(Targets,map[string]Target)
}

// Providers contains the configuration for the providers being used by the CI system.
Expand Down Expand Up @@ -132,6 +141,10 @@ package schema
} @go(Maps,map[string]string)
}
version: "1.0"
#Tagging: {
// Strategy contains the tagging strategy to use.
strategy: "commit" @go(Strategy)
}

// Target contains the configuration for a single target.
#Target: {
Expand Down
24 changes: 18 additions & 6 deletions blueprint/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@ type Project struct {
// Name contains the name of the project.
Name string `json:"name"`

// Container is the name that the container will be built as.
Container string `json:"container"`

// CI contains the configuration for the CI system.
// +optional
CI ProjectCI `json:"ci"`
}

type ProjectCI struct {
// Targets configures the individual targets that are run by the CI system.
// +optional
Targets map[string]Target `json:"targets"`
}

// CI contains the configuration for the CI system.
type GlobalCI struct {
// Providers contains the configuration for the providers being used by the CI system.
Expand All @@ -56,6 +53,16 @@ type GlobalCI struct {
// Registries contains the container registries to push images to.
// +optional
Registries []string `json:"registries"`

// Tagging contains the tagging configuration for the CI system.
// +optional
Tagging Tagging `json:"tagging"`
}

type ProjectCI struct {
// Targets configures the individual targets that are run by the CI system.
// +optional
Targets map[string]Target `json:"targets"`
}

// Providers contains the configuration for the providers being used by the CI system.
Expand Down Expand Up @@ -139,6 +146,11 @@ type Secret struct {
Maps map[string]string `json:"maps"`
}

type Tagging struct {
// Strategy contains the tagging strategy to use.
Strategy string `json:"strategy"`
}

// Target contains the configuration for a single target.
type Target struct {
// Args contains the arguments to pass to the target.
Expand Down
24 changes: 18 additions & 6 deletions blueprint/schema/schema_go_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ package schema
// Name contains the name of the project.
name: string @go(Name)

// Container is the name that the container will be built as.
container: string @go(Container)

// CI contains the configuration for the CI system.
// +optional
ci?: #ProjectCI @go(CI)
}

#ProjectCI: {
// Targets configures the individual targets that are run by the CI system.
// +optional
targets?: {[string]: #Target} @go(Targets,map[string]Target)
}

// CI contains the configuration for the CI system.
#GlobalCI: {
// Providers contains the configuration for the providers being used by the CI system.
Expand All @@ -50,6 +47,16 @@ package schema
// Registries contains the container registries to push images to.
// +optional
registries?: [...string] @go(Registries,[]string)

// Tagging contains the tagging configuration for the CI system.
// +optional
tagging?: #Tagging @go(Tagging)
}

#ProjectCI: {
// Targets configures the individual targets that are run by the CI system.
// +optional
targets?: {[string]: #Target} @go(Targets,map[string]Target)
}

// Providers contains the configuration for the providers being used by the CI system.
Expand Down Expand Up @@ -133,6 +140,11 @@ package schema
maps?: {[string]: string} @go(Maps,map[string]string)
}

#Tagging: {
// Strategy contains the tagging strategy to use.
strategy: string @go(Strategy)
}

// Target contains the configuration for a single target.
#Target: {
// Args contains the arguments to pass to the target.
Expand Down
9 changes: 9 additions & 0 deletions blueprint/schema/schema_overrides.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ package schema
#Blueprint: {
version: string & =~"^\\d+\\.\\d+"
}

#Project: {
name: _ & =~"^[a-z][a-z0-9_-]*$"
container: _ | *name
}

#Tagging: {
strategy: _ & "commit"
}
File renamed without changes.
45 changes: 45 additions & 0 deletions forge/actions/publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Discover Action

The discover action acts as a wrapper over the `forge scan` command from the Forge CLI.
It provides inputs that map to their respective flags.
The result from running the command is returned in the `result` output.
By default, the `--enumerate` flag is passed as this is usually the desired output format in CI.

For more information on the `scan` command, refer to the Forge CLI documentation.

## Usage

```yaml
name: Run Setup
on:
push:

permissions:
contents: read
id-token: write

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
uses: input-output-hk/catalyst-forge/forge/actions/setup@master
- name: Discover
id: discovery
uses: input-output-hk/catalyst-forge/forge/actions/discover@master
with:
filters: |
^check.*
^test.*
- name: Show result
run: echo "${{ steps.discovery.outputs.result }}
```
## Inputs
| Name | Description | Required | Default |
| --------- | --------------------------------------------- | -------- | --------- |
| absolute | Output absolute paths | No | `"false"` |
| enumerate | Enumerate results into Earthfile+Target pairs | No | `"true"` |
| filters | A newline separated list of filters to apply | No | `""` |
| path | The path to search from | No | `"."` |
13 changes: 13 additions & 0 deletions forge/actions/publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Publish
description: Publish container images
inputs:
project:
description: The path to the project
required: true
image:
description: The full image name (name:tag) to publish
required: true

runs:
using: node20
main: dist/index.js
Loading

0 comments on commit aec5da8

Please sign in to comment.