Skip to content

Commit

Permalink
Moved get-tested setup to own workflow (#47)
Browse files Browse the repository at this point in the history
* Moved get-tested setup to own workflow

This way it can be reused if one does need it in other places and not
only for build matrix generation.

* Ensure output directory exists

* Added workflow to test actions provided by this repository

* Forgot to checkout the repository first

* Try setting GH_TOKEN in setup-get-tested action

* Download release archive to RUNNER_TEMP

* Fixed: steps.setup.path -> steps.setup.outputs.path in setup-get-tested job
  • Loading branch information
mmhat committed Sep 3, 2024
1 parent 50332b5 commit 1a77bbc
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 14 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test actions pipeline

on:
pull_request:
branches: ['main']

push:
branches: ['main']

jobs:
test-action:
name: 'Test get-tested action'
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Extract the tested GHC versions
id: create-matrix
uses: ./
with:
cabal-file: get-tested.cabal
ubuntu-version: 'latest'
macos-version: 'latest'

- name: Output matrix
run: |
jq '.' <<< "${{ steps.create-matrix.matrix }}"
test-setup-action:
name: 'Test setup-get-tested action'
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up without options
id: setup
uses: ./setup-get-tested

- name: Set up with explicit directory
id: setup-with-directory
uses: ./setup-get-tested
with:
directory: "my-bin-dir"

- name: Output results
run: |
echo "${{ steps.setup.outputs.path }}"
if [[ -x "${{ steps.setup.outputs.path }}" ]]; then
echo "Is executable"
else
echo "Is NOT executable"
exit 1
fi
echo "${{ steps.setup-with-directory.outputs.path }}"
if [[ -x "${{ steps.setup-with-directory.outputs.path }}" ]]; then
echo "Is executable"
else
echo "Is NOT executable"
exit 1
fi
20 changes: 6 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,15 @@ runs:
steps:
- name: Checkout base repo
uses: actions/checkout@v4

- name: Set up get-tested
uses: ./setup-get-tested
with:
version: ${{ inputs.version }}

- name: Set up options
shell: bash
run: |
gh_release_flags=(
--repo Kleidukos/get-tested
--pattern 'get-tested-*-Linux-static-x86_64.tar.gz'
--output get-tested.tar.gz
)
if [[ "${{ inputs.version }}" != "" ]]
then
gh release download "v${{ inputs.version }}" "${gh_release_flags[@]}"
else
gh release download "${gh_release_flags[@]}"
fi
tar -xzvf get-tested.tar.gz
chmod +x get-tested
echo "::debug:: macOS: ${{ inputs.macos-version }}"
echo "::debug:: windows: ${{ inputs.windows-version }}"
echo "::debug:: ubuntu: ${{ inputs.ubuntu-version }}"
Expand Down
51 changes: 51 additions & 0 deletions setup-get-tested/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Set up get-tested"
description: "Fetches the get-tested tool"

inputs:
version:
description: "The version of the get-tested tool. Defaults to 'latest' if unspecified."
required: false
default: ""
directory:
description: "The directory where the get-tested executable should be placed."
required: false
default: "."

outputs:
path:
description: "The path to the get-tested executable."
value: ${{ steps.setup.outputs.path }}

runs:
using: "composite"
steps:
- name: Set up get-tested
id: setup
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
tmpdir="$(mktemp --directory "${RUNNER_TEMP}/setup-get-tested.XXX")"
trap "rm -rf ${tmpdir}" EXIT
gh_release_flags=(
--repo Kleidukos/get-tested
--pattern 'get-tested-*-Linux-static-x86_64.tar.gz'
--output "${tmpdir}/get-tested.tar.gz"
)
if [[ "${{ inputs.version }}" != "" ]]; then
gh release download "v${{ inputs.version }}" "${gh_release_flags[@]}"
else
gh release download "${gh_release_flags[@]}"
fi
mkdir -p "${{ inputs.directory }}"
tar -x -v -z -f "${tmpdir}/get-tested.tar.gz" -C "${{ inputs.directory }}"
path="${{ inputs.directory }}/get-tested"
chmod a+x "${path}"
echo "path=${path}" >> "${GITHUB_OUTPUT}"
branding:
icon: 'list'
color: 'blue'

0 comments on commit 1a77bbc

Please sign in to comment.