Skip to content

Commit

Permalink
feat: add the action, tests and dependabot setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Dec 10, 2024
1 parent f54ff6a commit b40ed90
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
63 changes: 63 additions & 0 deletions .github/workflows/test-setup-crossplane.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test Setup Crossplane
on:
push:
branches:
- main
paths:
- action.yaml
- .github/workflows/test-setup-crossplane.yml

pull_request:
branches:
- main
paths:
- action.yaml
- .github/workflows/test-setup-crossplane.yml
types:
- edited
- opened
- ready_for_review
- synchronize

merge_group:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
setup-crossplane:
runs-on: ubuntu-latest
env:
# generate a unique cache prefix for each test run, so we can test cache behaviour
CACHE_PREFIX: crossplane-${{ github.run_id }}-${{ github.run_attempt }}

strategy:
matrix:
cache-hit: [false, true]
max-parallel: 1

name: "Setup Crossplane (cache hit: ${{ matrix.cache-hit }})"

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
sparse-checkout: |
actions/setup-crossplane
- name: "Setup Crossplane (cache: ${{ matrix.cache-hit }})"
id: setup-crossplane
uses: ./
with:
cache-prefix: ${{ env.CACHE_PREFIX }}
version: v1.18.1

- name: Assert cache
if: fromJson(steps.setup-crossplane.outputs.cache-hit) != matrix.cache-hit
run: |
echo "Expected cache hit: '${{ matrix.cache-hit }}' but got '${{ fromJson(steps.setup-crossplane.outputs.cache-hit) }}'"
exit 1
- name: Check Crossplane CLI works
run: crossplane -h
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Setup Crossplane

Setup Crossplane cli and add it to the PATH, this action will run the install bash script and store the binary in cache for the next run.

## Example

<!-- x-release-please-start-version -->

```
uses: grafana/shared-workflows/actions/[email protected]
with:
version: v1.18.1 # Version of the Crossplane CLI to install.
```

<!-- x-release-please-end-version -->
60 changes: 60 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Setup Crossplane
description: Setup Crossplane cli and add it to the PATH, this action will run the install bash script and store the binary in cache for the next run.

inputs:
cache-prefix:
description: Prefix for the cache key.
default: crossplane

version:
description: |
Version of the Crossplane CLI to install.
default: v1.18.1

This comment has been minimized.

Copy link
@jbw976

jbw976 Dec 19, 2024

Member

should this be current instead, so by default it's always picking up the latest?

This comment has been minimized.

Copy link
@Duologic

Duologic Dec 20, 2024

Author Member

Good question, at Grafana Labs we tend to pin versions where we can and set up automation to update them, it'll prevent unexpected failures in case the behavior of 'current' changes (breaking change for example).

This comment has been minimized.

Copy link
@jbw976

jbw976 Dec 20, 2024

Member

would a new version of this action have to keep being released over time to update this default whenever there is a new Crossplane release? if so, it would be nice to not have to keep making new releases of this action. Consumers can still pin to a specific version and update that when they are ready if they want to go that (sensible) route. Maybe that's something Renovate could even do.

it's already behind now 😅
https://github.com/crossplane/crossplane/releases/tag/v1.18.2


channel:
description: |
Channel of the Crossplane CLI to install.
default: stable

outputs:
cache-hit:
description: Whether the cache was hit or not.
value: ${{ steps.cache.outputs.cache-hit || 'false' }}

runs:
using: composite

steps:
- name: Setup cache
id: cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ${{ github.workspace }}/bin/crossplane
key: ${{ inputs.cache-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }}

- run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
id: install
shell: bash
env:
XP_VERSION: ${{ inputs.version }}
XP_CHANNEL: ${{ inputs.channel }}

- name: move binary
id: move
if: steps.install.outcome == 'success'
shell: sh
run: |
mkdir -p ${{ github.workspace }}/bin
mv ./crossplane ${{ github.workspace }}/bin/crossplane
- name: Add binary to path
shell: sh
run: |
# Check if `crossplane` is already in the PATH
if command -v crossplane >/dev/null; then
echo "crossplane is already in the PATH, not re-adding it"
exit 0
fi
echo "Adding '${{ github.workspace }}/bin' to the PATH so the 'crossplane' binary can be found"
echo "${{ github.workspace }}/bin" >> "${GITHUB_PATH}"

0 comments on commit b40ed90

Please sign in to comment.