ノート: GitHub Actionsは、GitHub Enterprise Server 2.22で限定ベータとして利用可能でした。 ベータは終了しました。 GitHub Actionsは、GitHub Enterprise Server 3.0以降で一般に利用可能になりました。 詳しい情報については、GitHub Enterprise Server 3.0 のリリースノートを参照してください。
- GitHub Enterprise Server 3.0以降へのアップグレードに関する詳しい情報については「GitHub Enterprise Serverのアップグレード」を参照してください。
- アップグレード後のGitHub Actionsの設定に関する詳しい情報については、GitHub Enterprise Server 3.0のドキュメンテーションを参照してください。
ノート: 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.
警告: ワークフローやアクションを作る際には、攻撃者からの信頼できない入力をコードが実行するかもしれないことを、常に意識しなければなりません。 攻撃者が悪意あるコンテンツを挿入してくるかもしれないので、特定のコンテキストは信頼できない入力として扱うべきです。 詳しい情報については「スクリプトインジェクションのリスクを理解する」を参照してください。
必要な環境
始める前に、GitHub Enterprise Server リポジトリを作成します。
-
GitHub Enterprise Serverのインスタンス に新しいパブリックリポジトリを作成します。 You can choose any repository name, or use the following
hello-world-composite-actionexample. これらのファイルは、プロジェクトを GitHub Enterprise Serverにプッシュした後で追加できます。 詳しい情報については、「新しいリポジトリの作成」を参照してください。 -
リポジトリをお手元のコンピューターにクローンします。 詳しい情報についてはリポジトリのクローンを参照してください。
-
ターミナルから、ディレクトリを新しいリポジトリに変更します。
cd hello-world-composite-action -
In the
hello-world-composite-actionrepository, create a new file calledgoodbye.sh, and add the following example code:echo "Goodbye" -
ターミナルから、
goodbye.shを実行可能にします。chmod +x goodbye.sh -
ターミナルから、
goodbye.shファイルをチェックインします。git add goodbye.sh git commit -m "Add goodbye script" git push
アクションのメタデータファイルの作成
-
In the
hello-world-composite-actionrepository, create a new file calledaction.ymland add the following example code. For more information about this syntax, see "runsfor 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-id }} runs: using: "composite" steps: - run: echo Hello ${{ inputs.who-to-greet }}. shell: bash - id: random-number-generator run: echo "::set-output name=random-id::$(echo $RANDOM)" shell: bash - run: ${{ github.action_path }}/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 "
outputsfor a composite action".github.action_pathの使用方法の詳細については、「github context」を参照してください。 -
ターミナルから、
action.ymlファイルをチェックインします。git add action.yml git commit -m "Add action" git push -
ターミナルから、タグを追加します。 この例では、
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"スクリプトの結果、および乱数が含まれているはずです。