Skip to content

Commit f376ed7

Browse files
committed
init
0 parents  commit f376ed7

File tree

7 files changed

+438
-0
lines changed

7 files changed

+438
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '**.md'
9+
- '.github/**'
10+
11+
jobs:
12+
build-push:
13+
name: Build and push application image
14+
runs-on: ubuntu-latest
15+
permissions:
16+
id-token: write
17+
contents: read
18+
steps:
19+
20+
- name: Build and push application image
21+
uses: cloudbeds/composite-actions/docker/build-push/aws-ecr@v2
22+
with:
23+
# image_name: Only registry path is required. AWS ECR registry address will be automatically set by composite-actions
24+
image_name: ${{ github.event.repository.name }}
25+
image_tag: ${{ github.sha }}

.github/workflows/release-tag.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Re-tag images and Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
jobs:
10+
11+
re-tag:
12+
name: Re-tag image
13+
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write
16+
contents: read
17+
steps:
18+
19+
- name: Re-tag image application image
20+
uses: cloudbeds/composite-actions/docker/crane-re-tag/aws-ecr@v2
21+
with:
22+
# image_name: Only registry path is required. AWS ECR registry address will be automatically set by composite-actions
23+
image_name: ${{ github.event.repository.name }}
24+
src_tag: ${{ github.sha }}
25+
dst_tag: ${{ github.ref_name }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
TEMP.md
3+
.idea

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine:3.15.0
2+
3+
RUN apk update && \
4+
apk --no-cache add curl jq coreutils
5+
6+
COPY entrypoint.sh /entrypoint.sh
7+
8+
ENTRYPOINT ["sh", "/entrypoint.sh"]

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Trigger Workflow and Wait
2+
3+
Github Action for trigger a workflow from another workflow. The action then waits for a response.
4+
5+
**When would you use it?**
6+
7+
When deploying an app you may need to deploy additional services, this Github Action helps with that.
8+
9+
10+
## Arguments
11+
12+
| Argument Name | Required | Default | Description |
13+
| --------------------- | ---------- | ----------- | --------------------- |
14+
| `owner` | True | N/A | The owner of the repository where the workflow is contained. |
15+
| `repo` | True | N/A | The repository where the workflow is contained. |
16+
| `github_token` | True | N/A | The Github access token with access to the repository. Its recommended you put it under secrets. |
17+
| `workflow_file_name` | True | N/A | The reference point. For example, you could use main.yml. |
18+
| `github_user` | False | N/A | The name of the github user whose access token is being used to trigger the workflow. |
19+
| `ref` | False | main | The reference of the workflow run. The reference can be a branch, tag, or a commit SHA. |
20+
| `wait_interval` | False | 10 | The number of seconds delay between checking for result of run. |
21+
| `client_payload` | False | `{}` | Payload to pass to the workflow, must be a JSON string |
22+
| `propagate_failure` | False | `true` | Fail current job if downstream job fails. |
23+
| `trigger_workflow` | False | `true` | Trigger the specified workflow. |
24+
| `wait_workflow` | False | `true` | Wait for workflow to finish. |
25+
26+
27+
## Example
28+
29+
### Simple
30+
31+
```yaml
32+
- uses: cloudbeds/[email protected]
33+
with:
34+
owner: cloudbeds
35+
repo: myrepo
36+
github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }}
37+
```
38+
39+
### All Options
40+
41+
```yaml
42+
- uses: cloudbeds/[email protected]
43+
with:
44+
owner: cloudbeds
45+
repo: myrepo
46+
github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }}
47+
github_user: github-user
48+
workflow_file_name: main.yml
49+
ref: release-branch
50+
wait_interval: 10
51+
client_payload: '{}'
52+
propagate_failure: false
53+
trigger_workflow: true
54+
wait_workflow: true
55+
```
56+
57+
58+
## Testing
59+
60+
You can test out the action locally by cloning the repository to your computer. You can run:
61+
62+
```shell
63+
INPUT_OWNER="cloudbeds" \
64+
INPUT_REPO="myrepo" \
65+
INPUT_GITHUB_TOKEN="<REDACTED>" \
66+
INPUT_GITHUB_USER="github-user" \
67+
INPUT_WORKFLOW_FILE_NAME="main.yml" \
68+
INPUT_REF="release-branch" \
69+
INPUT_WAIT_INTERVAL=10 \
70+
INPUT_CLIENT_PAYLOAD='{}' \
71+
INPUT_PROPAGATE_FAILURE=false \
72+
INPUT_TRIGGER_WORKFLOW=true \
73+
INPUT_WAIT_WORKFLOW=true \
74+
busybox sh entrypoint.sh
75+
```
76+
77+
You will have to create a Github Personal access token. You can create a test workflow to be executed. In a repository, add a new `main.yml` to `.github/workflows/`. The workflow will be:
78+
79+
```shell
80+
name: Main
81+
on:
82+
workflow_dispatch
83+
jobs:
84+
build:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@master
88+
- name: Pause for 25 seconds
89+
run: |
90+
sleep 25
91+
```
92+
93+
You can see the example [here](https://github.com/cloudbeds/trigger-workflow-and-wait-example-repo1/blob/master/.github/workflows/main.yml). For testing a failure case, just add this line after the sleep:
94+
95+
```yaml
96+
...
97+
- name: Pause for 25 seconds
98+
run: |
99+
sleep 25
100+
echo "For testing failure"
101+
exit 1
102+
```
103+
104+
## Potential Issues
105+
106+
### Changes
107+
108+
If you do not want the latest build all of the time, please use a versioned copy of the Github Action. You specify the version after the `@` sign.
109+
110+
```yaml
111+
- uses: cloudbeds/[email protected]
112+
with:
113+
owner: cloudbeds
114+
repo: myrepo
115+
github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }}
116+
```

action.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Trigger Workflow and Wait'
2+
description: 'This action triggers a workflow in another repository and waits for the result.'
3+
author: 'Convictional'
4+
branding:
5+
icon: 'arrow-right'
6+
color: 'yellow'
7+
inputs:
8+
owner:
9+
description: "The owner of the repository where the workflow is contained."
10+
required: true
11+
repo:
12+
description: "The repository where the workflow is contained."
13+
required: true
14+
github_token:
15+
description: "The Github access token with access to the repository. Its recommended you put it under secrets."
16+
required: true
17+
github_user:
18+
description: "The name of the github user whose access token is being used to trigger the workflow."
19+
required: false
20+
ref:
21+
description: 'The reference of the workflow run. The reference can be a branch, tag, or a commit SHA. Default: main'
22+
required: false
23+
wait_interval:
24+
description: "The number of seconds delay between checking for result of run."
25+
required: false
26+
workflow_file_name:
27+
description: "The reference point. For example, you could use main.yml."
28+
required: true
29+
client_payload:
30+
description: 'Payload to pass to the workflow, must be a JSON string'
31+
required: false
32+
propagate_failure:
33+
description: 'Fail current job if downstream job fails. default: true'
34+
required: false
35+
trigger_workflow:
36+
description: 'Trigger the specified workflow. default: true'
37+
required: false
38+
wait_workflow:
39+
description: 'Wait for workflow to finish. default: true'
40+
required: false
41+
outputs:
42+
workflow_id:
43+
description: The ID of the workflow that was triggered by this action
44+
workflow_url:
45+
description: The URL of the workflow that was triggered by this action
46+
runs:
47+
using: 'docker'
48+
image: 'Dockerfile'

0 commit comments

Comments
 (0)