Skip to content

Commit

Permalink
Merge pull request #5 from grafana/4-add-release-workflow
Browse files Browse the repository at this point in the history
Add release workflow
  • Loading branch information
szkiba authored Nov 28, 2024
2 parents 90cda43 + 6613944 commit 6e12817
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 0 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: Release

on:
workflow_call:
inputs:
k6-version:
description: The version of k6 to be used
type: string
required: false
default: "latest"
go-version:
description: The version of Go to be used
type: string
required: false
default: "1.22.x"
os:
description: Target GOOS values
type: string
required: false
default: '["linux", "windows"]'
arch:
description: Target GOARCH values
type: string
required: false
default: '["amd64", "arm64"]'
with:
description: List of additional extension modules to be included
type: string
required: false
cgo:
description: Enable CGO
type: boolean

jobs:
config:
name: Config
runs-on: ubuntu-latest
outputs:
module-path: ${{steps.module.outputs.path}}
repository-name: ${{steps.repository.outputs.name}}
version: ${{steps.version.outputs.version}}
with: ${{steps.with.outputs.with}}
cgo: ${{steps.cgo.outputs.cgo}}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Detect go module path
id: module
shell: bash
run: |
echo "path=$(go list -f '{{.Module.Path}}')" >> $GITHUB_OUTPUT
- name: Parse repository name
id: repository
shell: bash
run: |
echo "name=$(echo ${{github.repository}}|cut -d/ -f2)" >> $GITHUB_OUTPUT
- name: Version from input or tag
id: version
shell: bash
run: |
if [ "${{github.ref_type}}" == "tag" ]; then
echo "version=${{github.ref_name}}" >> $GITHUB_OUTPUT
else
echo "The run was not triggered by a git tag push, so the 'version' parameter must be passed." >&2
exit 1
fi
- name: Prepare extra --with arguments
id: with
shell: bash
run: |
if [ -z "${{inputs.with}}" ]; then
exit 0
fi
value=`for part in $(echo "${{inputs.with}}"); do echo -n " --with $part" ; done`
echo "with=$value" >> $GITHUB_OUTPUT
- name: Prepare CGO environment valiable
id: cgo
shell: bash
run: |
cgo="0"
if [ "${{inputs.cgo}}" == "true" ]; then
cgo="1"
fi
echo "cgo=${cgo}" >> $GITHUB_OUTPUT
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: files
path: |
LICENSE*
README.md
build:
name: Build
needs:
- config
strategy:
matrix:
os: ${{ fromJSON(inputs.os) }}
arch: ${{ fromJSON(inputs.arch) }}
env:
DIST_DIR: ${{needs.config.outputs.repository-name}}_${{needs.config.outputs.version}}_${{matrix.os}}_${{matrix.arch}}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Setup Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Setup eget
uses: grafana/k6-extension-actions/[email protected]

- name: Setup xk6
uses: grafana/k6-extension-actions/[email protected]

- name: Build k6
shell: bash
env:
GOOS: ${{matrix.os}}
GOARCH: ${{matrix.arch}}
CGO: ${{needs.config.outputs.cgo}}
run: |
mkdir -p $DIST_DIR
cd $DIST_DIR
xk6 build ${{ inputs.k6-version }} --with ${{needs.config.outputs.module-path}}@${{needs.config.outputs.version}} ${{needs.config.outputs.with}}
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ${{env.DIST_DIR}}
name: files

- name: Create Archive
shell: bash
run: |
if [ "${{matrix.os}}" == "windows" ]; then
zip -r ${DIST_DIR}.zip $DIST_DIR
else
tar czf ${DIST_DIR}.tar.gz $DIST_DIR
fi
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
path: ${{env.DIST_DIR}}.*
name: archive-${{matrix.os}}_${{matrix.arch}}

publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- build
- config
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
pattern: archive-*

- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
tag_name: ${{needs.config.outputs.version}}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ Opinionated all-in-one workflow, fits most extensions.
![Visualization](docs/validate-light.png#gh-light-mode-only)

[Details](docs/validate.md)

## Release

Workflow for creating and attaching release artifacts.

![Visualization](docs/release-dark.png#gh-dark-mode-only)
![Visualization](docs/release-light.png#gh-light-mode-only)

[Details](docs/release.md)
Binary file added docs/release-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/release-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Release

Workflow for creating and attaching release artifacts.

![Visualization](release-dark.png#gh-dark-mode-only)
![Visualization](release-light.png#gh-light-mode-only)

### Usage

```yaml
name: Release

on:
push:
tags: ["v*.*.*"]

jobs:
release:
name: Release
uses: grafana/k6-extension-workflows/.github/workflows/[email protected]
```
### Inputs
Name | Default | Description
---------------|--------------------------|--------------------
`k6-version` | `latest` | The version of k6 to be used
`go-version` | `1.22.x` | The Go version to be used
`os` | `'["linux", "windows"]'` | Target `GOOS` values
`arch` | `'["amd64", "arm64"]'` | Target `GOARCH` values
`with` | | Additional extension modules
`cgo` | `false` | Enable CGO

### Jobs

#### Build

Build k6 for the operating systems and processor architectures specified as input parameters by embedding the extension. Additional extensions can be added using the `with` input parameter.

Release artifacts are created per platform from the `k6` executable and the `LICENSE` and `README.md` files.

#### Publish

Attach the created release artifacts to the release. If the release does not yet exist (only the tag), it will be created.

#### Config

Generate configuration output variables for other jobs.

0 comments on commit 6e12817

Please sign in to comment.