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

feat: adds multi-platform support for publish/release actions #32

Merged
merged 24 commits into from
Sep 11, 2024
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
37 changes: 17 additions & 20 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ on:
The version of the forge CLI to install (use 'local' for testing)
required: true
type: string
skip_branch_check:
description: If true, will always publish images, even on pushes to the non-default branch
required: false
type: string
default: "false"
secrets:
earthly_token:
description: Optional Earthly token used to login to Earthly cloud during local builds of Forge CLI
required: false

env:
CONTAINER: container
TAG: tag

jobs:
run:
name: ${{ matrix.earthfile }}
Expand All @@ -36,32 +45,20 @@ jobs:
uses: ./forge/actions/run
with:
path: ${{ matrix.earthfile }}
- name: Get image and project
id: image
if: github.ref_name == github.event.repository.default_branch
target_args: --container ${{ env.CONTAINER }} --tag ${{ env.TAG }}
- name: Parse Earthfile reference
id: parse
run: |
EARTHFILE='${{ matrix.earthfile }}'
PROJECT="${EARTHFILE%+*}"
TARGET="${EARTHFILE#*+}"
RESULT='${{ steps.run.outputs.result }}'

# If the path to the project is just ".", then we omit it
if [[ "$PROJECT" == "." ]]; then
EARTHFILE="+$TARGET"
fi

IMAGE="$(echo "$RESULT" | jq -r ".\"linux/amd64\".images[\"$EARTHFILE\"]")"

if [[ "$IMAGE" == "null" ]]; then
echo "::error file=${PROJECT}/Earthfile::No images produced. Cannot publish."
exit 1
fi

echo "image=$IMAGE" >> $GITHUB_OUTPUT
echo "project=$PROJECT" >> $GITHUB_OUTPUT
echo "target=$TARGET" >> $GITHUB_OUTPUT
- name: Publish
uses: ./forge/actions/publish
if: github.ref_name == github.event.repository.default_branch
with:
image: ${{ steps.image.outputs.image }}
project: ${{ steps.image.outputs.project }}
image: "${{ env.CONTAINER }}:${{ env.TAG }}"
project: ${{ steps.parse.outputs.project }}
skip_branch_check: ${{ inputs.skip_branch_check }}
target: ${{ steps.parse.outputs.target }}
21 changes: 6 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,19 @@ jobs:
with:
artifact: ${{ env.OUTPUT }}
path: ${{ matrix.earthfile }}
- name: Get project and artifacts
id: artifact
if: startsWith(github.ref, 'refs/tags/')
- name: Parse Earthfile reference
id: parse
run: |
EARTHFILE='${{ matrix.earthfile }}'
PROJECT="${EARTHFILE%+*}"
TARGET="${EARTHFILE#*+}"
RESULT='${{ steps.run.outputs.result }}'

ARTIFACT_COUNT="$(echo "$RESULT" | jq -r '.artifacts | length')"

if [[ $ARTIFACT_COUNT -eq 0 ]]; then
echo "::error file=${PROJECT}/Earthfile::No artifacts produced. Nothing to release."
exit 1
fi

ls -l ${{ env.OUTPUT }}

echo "project=$PROJECT" >> $GITHUB_OUTPUT
echo "target=$TARGET" >> $GITHUB_OUTPUT
- name: Release
uses: ./forge/actions/release
if: startsWith(github.ref, 'refs/tags/')
with:
native_platform: linux/amd64
path: ${{ env.OUTPUT }}
project: ${{ steps.artifact.outputs.project }}
project: ${{ steps.parse.outputs.project }}
target: ${{ steps.parse.outputs.target }}
7 changes: 7 additions & 0 deletions forge/actions/publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ inputs:
image:
description: The full image name (name:tag) to publish
required: true
skip_branch_check:
description: If true, will always publish images, even on pushes to the non-default branch
required: false
default: "false"
target:
description: The Earthly target that was run
required: true

runs:
using: node20
Expand Down
Loading