Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/container-actionPublic template

License

NotificationsYou must be signed in to change notification settings

actions/container-action

Repository files navigation

Continuous IntegrationLinter

Use this template to bootstrap the creation of a container action. 🚀

This template includes compilation support, tests, a validation workflow,publishing, and versioning guidance.

Create Your Own Action

To create your own action, you can use this repository as a template! Justfollow the below instructions:

  1. Click theUse this template button at the top of the repository
  2. SelectCreate a new repository
  3. Select an owner and name for your new repository
  4. ClickCreate repository
  5. Clone your new repository

Important

Make sure to remove or update theCODEOWNERS file! Fordetails on how to use this file, seeAbout code owners.

Initial Setup

After you've cloned the repository to your local machine or codespace, you'llneed to perform some initial setup steps before you can develop your action.

Note

You'll need to have a reasonably modern version ofDocker handy (e.g. docker engineversion 20 or later).

  1. 🛠️ Build the container

    Make sure to replaceactions/container-action with an appropriate label foryour container.

    docker build -t actions/container-action.
  2. ✅ Test the container

    You can pass individual environment variables using the--env or-e flag.

    $ docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/container-action::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!

    Or you can pass a file with environment variables using--env-file.

    $ cat ./.env.testINPUT_WHO_TO_GREET="Mona Lisa Octocat"$ docker run --env-file ./.env.test actions/container-action::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!

Update the Action Metadata

Theaction.yml file defines metadata about your action, such asinput(s) and output(s). For details about this file, seeMetadata syntax for GitHub Actions.

When you copy this repository, updateaction.yml with the name, description,inputs, and outputs for your action.

Update the Action Code

In this template, the container action runs a shell script,entrypoint.sh, when the container is launched. Since youcan choose any base Docker image and language you like, you can change this tosuite your needs. There are a few main things to remember when writing code forcontainer actions:

  • Inputs are accessed using argument identifiers or environment variables(depending on what you set in youraction.yml). For example, the first inputto this action,who-to-greet, can be accessed in the entrypoint script usingthe$INPUT_WHO_TO_GREET environment variable.

    GREETING="Hello,$INPUT_WHO_TO_GREET!"
  • GitHub Actions supports a number of different workflow commands such ascreating outputs, setting environment variables, and more. These areaccomplished by writing to differentGITHUB_* environment variables. Formore information, seeWorkflow commands.

    ScenarioExample
    Set environment varsecho "MY_VAR=my-value" >> "$GITHUB_ENV"
    Set outputsecho "greeting=$GREETING" >> "$GITHUB_OUTPUT"
    Prepend toPATHecho "$HOME/.local/bin" >> "$GITHUB_PATH"
    Setpre/post varsecho "MY_VAR=my-value" >> "$GITHUB_STATE"
    Set step summaryecho "{markdown}" >> "$GITHUB_STEP_SUMMARY"

    You can write multiline strings using the following syntax:

    {echo"JSON_RESPONSE<<EOF"  curl https://example.comecho"EOF"}>>"$GITHUB_ENV"
  • Make sure that the script being run is executable!

    git add entrypoint.shgit update-index --chmod=+x entrypoint.sh

So, what are you waiting for? Go ahead and start customizing your action!

  1. Create a new branch

    git checkout -b releases/v1
  2. Replace the contents ofentrypoint.sh with your action code

  3. Build and test the container

    docker build -t actions/container-action.docker run actions/container-action"Mona Lisa Octocat"
  4. Commit your changes

    git add.git commit -m"My first action is ready!"
  5. Push them to your repository

    git push -u origin releases/v1
  6. Create a pull request and get feedback on your action

  7. Merge the pull request into themain branch

Your action is now published! 🚀

For information about versioning your action, seeVersioningin the GitHub Actions toolkit.

Validate the Action

You can now validate the action by referencing it in a workflow file. Forexample,ci.yml demonstrates how to reference anaction in the same repository.

steps:  -name:Checkoutid:checkoutuses:actions/checkout@v4  -name:Test Local Actionid:test-actionuses:./with:who-to-greet:Mona Lisa Octocat  -name:Print Outputid:outputrun:echo "${{ steps.test-action.outputs.greeting }}"

For example workflow runs, check out theActions tab! 🚀

Usage

After testing, you can create version tag(s) that developers can use toreference different stable versions of your action. For more information, seeVersioningin the GitHub Actions toolkit.

To include the action in a workflow in another repository, you can use theuses syntax with the@ symbol to reference a specific branch, tag, or commithash.

steps:  -name:Checkoutid:checkoutuses:actions/checkout@v4  -name:Test Local Actionid:test-actionuses:actions/container-action@v1# Commit with the `v1` tagwith:who-to-greet:Mona Lisa Octocat  -name:Print Outputid:outputrun:echo "${{ steps.test-action.outputs.greeting }}"

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp