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 release action #17

Merged
merged 8 commits into from
Sep 6, 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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
^check.*
^test.*
publish
release

check:
uses: ./.github/workflows/run.yml
Expand Down Expand Up @@ -54,4 +55,11 @@ jobs:
needs: [discover, check, build, test]
with:
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['publish']) }}
forge_version: ${{ inputs.forge_version }}

release:
uses: ./.github/workflows/release.yml
needs: [discover, check, build, test]
with:
earthfiles: ${{ toJson(fromJson(needs.discover.outputs.result)['release']) }}
forge_version: ${{ inputs.forge_version }}
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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

env:
OUTPUT: ${{ github.workspace }}/output

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:
artifact: ${{ env.OUTPUT }}
path: ${{ matrix.earthfile }}
- name: Get project and artifacts
id: artifact
if: startsWith(github.ref, 'refs/tags/')
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
- name: Release
uses: ./forge/actions/release
if: startsWith(github.ref, 'refs/tags/')
with:
path: ${{ env.OUTPUT }}
project: ${{ steps.artifact.outputs.project }}
49 changes: 49 additions & 0 deletions forge/actions/release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Release Action

The release action creates a new GitHub release and uploads artifacts to it.
It automatically handles parsing git tags in order to generate the release name.

## Usage

```yaml
name: Run Release
on:
push:

permissions:
contents: read
id-token: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Setup
uses: input-output-hk/catalyst-forge/forge/actions/setup@master
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: input-output-hk/catalyst-forge/forge/actions/release@master
with:
project: ./my/project/path
path: ./path/to/artifacts
```

The action should only be run when a git tag is present.
The given project is used to determine whether a release should happen or not:

- If the git tag is a mono-repo tag and it matches the given project, then a release is made
- If the git tag is not a mono-repo tag, a release always occurs

The release is named the same as the git tag.
The given `path` is archived in a `.tar.gz` file and uploaded as an asset for the release.
The name of the archive depends on the git tag:

- If the git tag is a mono-repo tag, the archive is named in the format of: `<prefix>-<platform>.tar.gz`
- If the git tag is not a mono-repo tag, the archive is named in the format of: `<repo_name>-<platform>.tar.gz`

## Inputs

| Name | Description | Required | Default |
| ------- | -------------------------------------------------- | -------- | ------- |
| project | The relative path to the project (from git root) | Yes | N/A |
| path | The path to any artifacts to attach to the release | Yes | N/A |
21 changes: 21 additions & 0 deletions forge/actions/release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release
description: Create a new GitHub release and upload generated artifacts
inputs:
github_token:
description: The token to use for creating a new release
required: false
default: ${{ github.token }}
project:
description: The path to the project
required: true
path:
description: The path to generated artifacts
required: true
platform:
description: The platform the artifacts are targeting
required: false
default: "linux-amd64"

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