You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/actions/creating-actions/creating-a-docker-container-action.md
+17-18
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Before you begin, you'll need to create a GitHub repository.
39
39
40
40
1. From your terminal, change directories into your new repository.
41
41
42
-
```shell
42
+
```shell{:copy}
43
43
cd hello-world-docker-action
44
44
```
45
45
@@ -48,7 +48,7 @@ Before you begin, you'll need to create a GitHub repository.
48
48
In your new `hello-world-docker-action` directory, create a new `Dockerfile` file. For more information, see "[Dockerfile support for {% data variables.product.prodname_actions %}](/actions/creating-actions/dockerfile-support-for-github-actions)."
49
49
50
50
**Dockerfile**
51
-
```dockerfile
51
+
```dockerfile{:copy}
52
52
# Container image that runs your code
53
53
FROM alpine:3.10
54
54
@@ -65,7 +65,7 @@ Create a new `action.yml` file in the `hello-world-docker-action` directory you
65
65
66
66
{% raw %}
67
67
**action.yml**
68
-
```yaml
68
+
```yaml{:copy}
69
69
# action.yml
70
70
name: 'Hello World'
71
71
description: 'Greet someone and record the time'
@@ -93,29 +93,28 @@ This metadata defines one `who-to-greet` input and one `time` output parameter.
93
93
94
94
You can choose any base Docker image and, therefore, any language for your action. The following shell script example uses the `who-to-greet` input variable to print "Hello [who-to-greet]" in the log file.
95
95
96
-
Next, the script gets the current time and sets it as an output variable that actions running later in a job can use. In order for {% data variables.product.prodname_dotcom %} to recognize output variables, you must use a workflow command in a specific syntax: `echo "::set-output name=<output name>::<value>"`. For more information, see "[Workflow commands for {% data variables.product.prodname_actions %}](/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter)."
96
+
Next, the script gets the current time and sets it as an output variable that actions running later in a job can use. In order for {% data variables.product.prodname_dotcom %} to recognize output variables, you must use a workflow command in a specific syntax: `echo "::set-output name=<output name>::<value>"`. For more information, see "[Workflow commands for {% data variables.product.prodname_actions %}](/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter)."
97
97
98
98
1. Create a new `entrypoint.sh` file in the `hello-world-docker-action` directory.
99
99
100
-
1. Make your `entrypoint.sh` file executable:
101
-
102
-
```shell
103
-
chmod +x entrypoint.sh
104
-
```
105
-
106
100
1. Add the following code to your `entrypoint.sh` file.
107
101
108
102
**entrypoint.sh**
109
-
```shell
103
+
```shell{:copy}
110
104
#!/bin/sh -l
111
105
112
106
echo "Hello $1"
113
107
time=$(date)
114
108
echo "::set-output name=time::$time"
115
109
```
116
-
117
110
If `entrypoint.sh` executes without any errors, the action's status is set to `success`. You can also explicitly set exit codes in your action's code to provide an action's status. For more information, see "[Setting exit codes for actions](/actions/creating-actions/setting-exit-codes-for-actions)."
118
111
112
+
1. Make your `entrypoint.sh` file executable by running the following command on your system.
113
+
114
+
```shell{:copy}
115
+
$ chmod +x entrypoint.sh
116
+
```
117
+
119
118
### Creating a README
120
119
121
120
To let people know how to use your action, you can create a README file. A README is most helpful when you plan to share your action publicly, but is also a great way to remind you or your team how to use the action.
@@ -130,7 +129,7 @@ In your `hello-world-docker-action` directory, create a `README.md` file that sp
130
129
- An example of how to use your action in a workflow.
131
130
132
131
**README.md**
133
-
```markdown
132
+
```markdown{:copy}
134
133
# Hello world docker action
135
134
136
135
This action prints "Hello World" or "Hello" + the name of a person to greet to the log.
@@ -160,7 +159,7 @@ From your terminal, commit your `action.yml`, `entrypoint.sh`, `Dockerfile`, and
160
159
161
160
It's best practice to also add a version tag for releases of your action. For more information on versioning your action, see "[About actions](/actions/automating-your-workflow-with-github-actions/about-actions#using-release-management-for-actions)."
@@ -175,11 +174,11 @@ Now you're ready to test your action out in a workflow. When an action is in a p
175
174
176
175
#### Example using a public action
177
176
178
-
The following workflow code uses the completed hello world action in the public [`actions/hello-world-docker-action`](https://github.com/actions/hello-world-docker-action) repository. Copy the following workflow example code into a `.github/workflows/main.yml` file, but replace the `actions/hello-world-docker-action` with your repository and action name. You can also replace the `who-to-greet` input with your name.
177
+
The following workflow code uses the completed _hello world_ action in the public [`actions/hello-world-docker-action`](https://github.com/actions/hello-world-docker-action) repository. Copy the following workflow example code into a `.github/workflows/main.yml` file, but replace the `actions/hello-world-docker-action` with your repository and action name. You can also replace the `who-to-greet` input with your name. {% if currentVersion == "free-pro-team@latest" %}Public actions can be used even if they're not published to {% data variables.product.prodname_marketplace %}. For more information, see "[Publishing an action](/actions/creating-actions/publishing-actions-in-github-marketplace#publishing-an-action)." {% endif %}
179
178
180
179
{% raw %}
181
180
**.github/workflows/main.yml**
182
-
```yaml
181
+
```yaml{:copy}
183
182
on: [push]
184
183
185
184
jobs:
@@ -200,11 +199,11 @@ jobs:
200
199
201
200
#### Example using a private action
202
201
203
-
Copy the following example workflow code into a `.github/workflows/main.yml` file in your action's repository. You can also replace the `who-to-greet` input with your name.
202
+
Copy the following example workflow code into a `.github/workflows/main.yml` file in your action's repository. You can also replace the `who-to-greet` input with your name. {% if currentVersion == "free-pro-team@latest" %}This private action can't be published to {% data variables.product.prodname_marketplace %}, and can only be used in this repository.{% endif %}
0 commit comments