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

add init hooks #56

Merged
merged 1 commit into from
Jan 29, 2024
Merged

add init hooks #56

merged 1 commit into from
Jan 29, 2024

Conversation

lsviben
Copy link
Contributor

@lsviben lsviben commented Jan 19, 2024

Description of your changes

Adds NOTES.txt and init.sh script to be caught by the new crossplane beta init command hooks when initialising the repo.

Using perl instead of sed for replace so that its platform-agnostic. AFAIK most unix systems have it pre-installed. But could be wrong of course, or somebody has a better idea, let me know.

I have:

  • Read and followed Crossplane's contribution process.
  • [] Added or updated unit tests for my change.

Test

~/go/crossplane/_output/bin/darwin_arm64/crank beta xpkg init func https://github.com/lsviben/function-template-go -d func20
Initialized package "func" in directory "/tmp/t/func20" from https://github.com/lsviben/function-template-go/tree/a2d0b2360b28983ef4b72861dc0657f089ede57b (main)

To get started:

1. Replace `function-template-go` with your function in `go.mod`,
   `package/crossplane.yaml`, and any Go imports. (You can also do this
   automatically by running the `./init.sh <function-name>` script.)
2. Update `input/v1beta1/` to reflect your desired input (and run `go generate`)
3. Add your logic to `RunFunction` in `fn.go`
4. Add tests for your logic in `fn_test.go`
5. Update `README.md`, to be about your function!

Found init.sh script!
Do you want to run it? [y]es/[n]o/[v]iew: v

#!/bin/sh

# This script helps initialize a new function project by
# replacing all instances of function-template-go with the
# name of your function. The scripts accepts two arguments:
# 1. The name of your function
# 2. The path to your function directory

set -e

cd "$2" || return

# Replace function-template-go with the name of your function
# in go.mod
perl -pi -e s,function-template-go,"$1",g go.mod
# in fn.go
perl -pi -e s,function-template-go,"$1",g fn.go
# in examples
perl -pi -e s,function-template-go,"$1",g example/*

echo "Function $1 has been initialised successfully"

Do you want to run it? [y]es/[n]o/[v]iew: y
Function func has been initialised successfully

Signed-off-by: lsviben <[email protected]>
@phisco phisco merged commit e7de668 into crossplane:main Jan 29, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants