Skip to main content
ドキュメントには� �繁に更新が� えられ、その都度公開されています。本ページの翻訳はま� 未完成な部分があることをご了承く� さい。最新の情� �については、英語のドキュメンテーションをご参照く� さい。本ページの翻訳に問題がある� �合はこちらまでご連絡く� さい。

このバージョンの GitHub Enterprise はこの日付をもって終了となりました: 2022-06-03. 重大なセキュリティの問題に対してであっても、パッチリリースは作成されません。 パフォーマンスの向上、セキュリティの改善、新機能のためには、最新バージョンのGitHub Enterpriseにアップグレードしてく� さい。 アップグレードに関する支援については、GitHub Enterprise supportに連絡してく� さい。

Creating a composite action

In this guide, you'll learn how to build a composite action.

ノート: GitHubホストランナーは、現在GitHub Enterprise Serverでサポートされていません。 GitHubパブリックロードマップで、計画されている将来のサポートに関する詳しい情� �を見ることができます。

はじめに

In this guide, you'll learn about the basic components needed to create and use a packaged composite action. アクションのパッケージ化に必要なコンポーネントのガイドに焦点を当てるため、アクションのコードの機能は最小限に留めます。 アクションは「Hello World」と「Goodbye」を出力するか、カスタ� の名前を指定すると「Hello [who-to-greet]」と「Goodbye」を出力します。 このアクションは、乱数を random-numberという出力変数にマップし、 goodbye.shという名前のスクリプトを実行することもします。

Once you complete this project, you should understand how to build your own composite action and test it in a workflow.

警告: ワークフローやアクションを作る際には、攻撃者からの信� �できない入力をコードが実行するかもしれないことを、常に意識しなければなりません。 攻撃者が悪意あるコンテンツを挿入してくるかもしれないので、特定のコンテキストは信� �できない入力として扱うべきです。 詳しい情� �については「スクリプトインジェクションのリスクを理解する」を参照してく� さい。

必要な環境

Before you begin, you'll create a repository on GitHub Enterprise Serverインスタンス.

  1. GitHub Enterprise Serverインスタンス に新しいパブリックリポジトリを作成します。 You can choose any repository name, or use the following hello-world-composite-action example. これらのファイルは、プロジェクトを GitHub Enterprise Serverにプッシュした後で追� できます。 詳しい情� �については、「新しいリポジトリの作成」を参照してく� さい。

  2. リポジトリをお手元のコンピューターにクローンします。 詳しい情� �についてはリポジトリのクローンを参照してく� さい。

  3. ターミナルから、ディレクトリを新しいリポジトリに変更します。

    cd hello-world-composite-action
  4. In the hello-world-composite-action repository, create a new file called goodbye.sh, and add the following example code:

    echo "Goodbye" 
  5. ターミナルから、goodbye.sh を実行可能にします。

    chmod +x goodbye.sh
  6. ターミナルから、 goodbye.sh ファイルをチェックインします。

    git add goodbye.sh git commit -m "Add goodbye script" git push

アクションのメタデータファイルの作成

  1. In the hello-world-composite-action repository, create a new file called action.yml and add the following example code. For more information about this syntax, see "runs for a composite actions".

    action.yml

    name: 'Hello World' description: 'Greet someone' inputs: who-to-greet: # id of input description: 'Who to greet' required: true default: 'World' outputs: random-number: description: "Random number" value: ${{ steps.random-number-generator.outputs.random-number }} runs: using: "composite" steps: - run: echo Hello ${{ inputs.who-to-greet }}. shell: bash - id: random-number-generator run: echo "::set-output name=random-number::$(echo $RANDOM)" shell: bash - run: echo "${{ github.action_path }}" >> $GITHUB_PATH shell: bash - run: goodbye.sh shell: bash 

    このファイルはwho-to-greet入力を定義し、ランダ� に生成された数値をrandom-number出力変数にマップし、goodbye.shスクリプトを実行します。 It also tells the runner how to execute the composite action.

    For more information about managing outputs, see "outputs for a composite action".

    github.action_pathの使用方法の詳細については、「github context」を参照してく� さい。

  2. ターミナルから、action.yml ファイルをチェックインします。

    git add action.yml git commit -m "Add action" git push
  3. ターミナルから、タグを追� します。 この例では、v1 というタグを使用しています。 詳しい情� �については、「Actionsについて」を参照してく� さい。

    git tag -a -m "Description of this release" v1 git push --follow-tags

ワークフローでアクションをテストする

次のワークフローのコードでは、「Actionsのメタデータファイルの作成」で作成したhello world Actionを使用しています。

Copy the workflow code into a .github/workflows/main.yml file in another repository, but replace actions/hello-world-composite-action@v1 with the repository and tag you created. who-to-greetの入力を自分の名前に置き換えることもできます。

.github/workflows/main.yml

on: [push] jobs: hello_world_job: runs-on: ubuntu-latest name: A job to say hello steps: - uses: actions/checkout@v2 - id: foo uses: actions/hello-world-composite-action@v1 with: who-to-greet: 'Mona the Octocat' - run: echo random-number ${{ steps.foo.outputs.random-number }} shell: bash 

リポジトリから [Actions] タブをクリックして、最新のワークフロー実行を選択します。 出力には、「Hello Mona the Octocat」、"Goodbye"スクリプトの結果、および乱数が含まれているはずです。