This repository is a template repository for writing GitHub Actions in Golang. It is based on the GitHub Action documentation and references the GitHub Node.js SDK.
In a sense, the way this repository is implemented has a bit of action-as-code flavor to it。
First. You need to use this template repository to create a repository, the details of which can be found in the official GitHub documentation
You can pull the created repository locally using the following command
mkdir action-go-template;
cd action-go-template;
git init;
git remote add origin [email protected]:guguducken/action-go-template.git;
git pull origin main;
Just replace the repository information with your own.
Personally I think this section is the key to what this repository can be called action-as-code, you can go through the following steps by modifying the code and generating action.yaml
-
Modifying information in the
Makefile
There is some information defined in the
Makefile
that is used to generate thego module
and theaction yaml
, which needs to be changed to the actual repository information... # You must modify it to yourself information AUTHOR=guguducken REPOSITORY=action-go-template DESCRIPTION=A template repository for creating action written in go language. ICON=arrow-up COLOR=blue ...
For example, it can be modified to this
... # You must modify it to yourself information AUTHOR=guguducken REPOSITORY=upload-artifact-oss DESCRIPTION=Upload an artifact to oss. ICON=arrow-up COLOR=blue ...
-
Initialization go module settings
After you have made the above changes, you can use the following commands to complete the initialization of the
go module
make preconfig
After executing this command, you need to make sure that the information has been changed
-
Setting up GitHub action inputs, outputs, and other information
This information is defined in the file
optools/action/action-helper.go
, the fields are annotated and can be modified according to the annotations.After modifying the corresponding information, you can generate the action yaml with the following command.
make action
If there are changes, the action yaml can be regenerated by running this command again
-
Add the code which needs
Just add the actual code,
main.go
is the only entry point for the code.Finally, the binary can be generated by following command
make build
-
Publish your action