Skip to content

Commit a3fb01b

Browse files
authored
Merge pull request #32 from camihmerhar/Infomagnus-SubOD-3.1.2-3.1.5
updated content based on feedback
2 parents b66e90a + 2d4f737 commit a3fb01b

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

learn-pr/github/create-custom-github-actions/includes/create-custom-github-action.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Composite run steps actions allow you to reuse actions by using shell scripts. Y
3636

3737
# Packaged Composite Action
3838

39-
Packaged composite actions bundle multiple steps into a reusable unit. These actions are defined in a repository and can be referenced in workflows across different repositories. By packaging a composite action, workflows are simplified, duplication is reduced, and maintainability is improved.
39+
Packaged composite actions bundle multiple steps into a reusable unit. These actions are defined in a repository and can be referenced in workflows across different repositories. Packaging a composite action simplifies workflows, reduces duplication, and improves maintainability.
4040

4141
When creating a packaged composite action, the steps are defined in a single `action.yml` file. This file specifies the inputs, outputs, and the sequence of commands or actions to execute. Packaged composite actions are particularly useful for automating repetitive tasks or combining multiple shell commands into a single reusable action.
4242

@@ -96,9 +96,13 @@ If your composite action is shared from **another repository**, reference it lik
9696
uses: owner/repository/.github/actions/my-composite-action@v1
9797
```
9898
## Adding Outputs to a Composite Action
99-
Composite actions can define outputs that can be used in workflows.
99+
Composite actions can define outputs that workflows can use to pass data between steps or jobs. Outputs are particularly useful for sharing results or computed values from one action to another.
100100
101-
### 1. Define an Output in action.yml
101+
The following example demonstrates how to define and use an output in a composite action:
102+
103+
#### Define an Output in `action.yml`
104+
105+
The `action.yml` file specifies an output named `script-result`. This output retrieves its value from the `result` output of the `run-script` step. The `run-script` step runs a Bash command to set the output value.
102106

103107
```yaml
104108
outputs:
@@ -113,7 +117,11 @@ runs:
113117
run: echo "result=Success" >> $GITHUB_OUTPUT
114118
shell: bash
115119
```
116-
### 2. Access the Output in a Workflow
120+
121+
#### Use the Output in a Workflow
122+
123+
Once the composite action is created, its output can be accessed in a workflow. Here's an example:
124+
117125
```yaml
118126
jobs:
119127
test:
@@ -127,6 +135,13 @@ jobs:
127135
run: echo "Script Result: ${{ steps.my-action.outputs.script-result }}"
128136
```
129137

138+
In this example:
139+
- The composite action is invoked using the `uses` keyword.
140+
- Access the output `script-result` using the `steps.<step-id>.outputs.<output-name>` syntax.
141+
- Display the result in the workflow logs.
142+
143+
Define outputs in composite actions to create reusable and modular workflows. This approach simplifies data sharing and improves maintainability.
144+
130145
## Best Practices for Composite Actions
131146

132147
| **Best Practice** | **Description** |
@@ -233,8 +248,7 @@ async function run() {
233248

234249
run();
235250
```
236-
**Explanation:**
237-
The JavaScript action uses `core.getInput()` to retrieve the CLI version specified as input. It then executes a `curl` command to download and install the CLI. If the installation process fails, the action uses `core.setFailed()` to mark the workflow as failed.
251+
The JavaScript code above uses core.getInput() to retrieve the CLI version specified as input. It then executes a curl command to download and install the CLI. If the installation process fails, the action uses core.setFailed() to mark the workflow as failed.
238252

239253
### Step 4: Test the Action Locally
240254
Before using the action in a workflow, test it on a GitHub-hosted runner.
@@ -247,28 +261,38 @@ on:
247261
branches:
248262
- main
249263
- feature/*
264+
```
265+
**a. Triggering the Workflow**
266+
The workflow is triggered on pushes to the main branch and any branch matching the feature/* pattern. You can adjust this to match your repository's branching strategy.
250267
268+
```yaml
251269
jobs:
252270
test:
253271
runs-on: ubuntu-latest
254272
steps:
255273
- name: Checkout repository
256274
uses: actions/checkout@v4
275+
```
276+
**b. Checkout the Repository**
277+
The *actions/checkout@v4* action is used to clone the repository onto the runner. This ensures that the workflow has access to the repository's files.
257278
279+
```yaml
258280
- name: Install MyCLI
259281
uses: ./.github/actions/my-cli-action
260282
with:
261283
version: '1.2.3'
284+
```
285+
**c. Run the Custom Action**
286+
The uses: *./.github/actions/my-cli-action* line references the custom action locally. Ensure that the action directory and action.yml file are correctly set up. The version input specifies the CLI version to install—in this case, version 1.2.3.
262287
288+
```yaml
263289
- name: Verify CLI Installation
264290
run: |
265291
echo "Checking MyCLI version..."
266292
mycli --version
267293
```
268-
### Key Notes:
269-
1. **Branch Selection**: The workflow triggers on pushes to the `main` branch and any branch matching the `feature/*` pattern. Adjust this as needed for your repository.
270-
2. **Action Reference**: The `uses: ./.github/actions/my-cli-action` line references the custom action locally. Ensure the action directory and `action.yml` file are correctly set up.
271-
3. **CLI Version Input**: The `version` input specifies the CLI version to install. Update this value as required.
294+
**d. Verify the CLI Installation**
295+
This step runs a shell command to verify that the CLI was installed successfully. It checks the version of the installed CLI by running mycli --version.
272296
273297
### Testing Locally
274298
To test this workflow locally, use the [`act`](https://github.com/nektos/act) CLI tool:

0 commit comments

Comments
 (0)