Skip to content

Dispatch example #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions .github/workflows/dispatch-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: GitHub action dispath
on:
workflow_dispatch:
inputs:
source-regurl-tag:
source_regurl_tag:
required: true
default: ""
description: "Container image registry URL with tag. e.g., gcr.io/project-id-372417/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2"
target-regurl:
target_regurl:
required: true
default: ""
description: "Container image registry URL WITHOUT tag e.g., gcr.io/project-id-372417/target-image"
Expand All @@ -17,17 +17,23 @@ jobs:
name: Copy container image
runs-on: ubuntu-latest
env:
SOURCE_IMAGE_WITH_TAG: ${{ github.env.inputs.source-regurl-tag }}
TARGET_IMAGE_URL: ${{ github.env.inputs.target-regurl }}
IMAGE_TAG: ''
PROD_IMAGE: ''
steps:
- name: print
run: |
echo ${{ inputs.source_regurl_tag }}
echo ${{ inputs.target-tag }}
- name: Get image tag
run: |
echo IMAGE_TAG=$(echo ${{ env.SOURCE_IMAGE_WITH_TAG }} | cut -d":" -f2) >> $GITHUB_ENV
echo IMAGE_TAG=$(echo ${{ inputs.source_regurl_tag }} | cut -d":" -f2) >> $GITHUB_ENV
echo "PROD_IMAGE=${{ inputs.target_regurl }}:${{ env.IMAGE_TAG }}" >> $GITHUB_ENV

- name: Summary
run: |
echo "SOURCE_IMAGE_WITH_TAG=${{ env.SOURCE_IMAGE_WITH_TAG }}" >> $GITHUB_STEP_SUMMARY
echo "PROD_IMAGE=${{ env.TARGET_IMAGE_URL }}:${{ env.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY
echo "source_regurl_tag: ${{ inputs.source_regurl_tag }}" >> $GITHUB_STEP_SUMMARY
echo "target_regurl: ${{ inputs.target_regurl }}" >> $GITHUB_STEP_SUMMARY
echo "PROD_IMAGE: ${{ env.PROD_IMAGE }}" >> $GITHUB_STEP_SUMMARY

- uses: hmarr/debug-action@v2
if: always()
4 changes: 2 additions & 2 deletions .github/workflows/dispatch-request-exmple.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ref": "develop",
"inputs": {
"source-url-tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"target-url": "gcr.io/project-id/target-image"
"source_regurl_tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"target_regurl": "gcr.io/project-id/target-image"
}
}
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ Provides GitHub Workflow and Action samples.
cp .github/workflows/dispatch-request-exmple.json request-body.json
cat request-body.json

TOKEN="example-github_pat_XXXXX"

curl -d @request-body.json \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer <your-token>" \
https://github.com/DevSecOpsSamples/githubactions/actions/workflows/dispatch-example.yml/dispatches
-H "Authorization: Bearer $TOKEN" \
https://api.github.com/repos/DevSecOpsSamples/githubactions/actions/workflows/dispatch-example.yml/dispatches
```

develop branch:
Expand All @@ -86,8 +88,8 @@ develop branch:
{
"ref": "develop",
"inputs": {
"test-url-tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"prod-url": "gcr.io/project-id/target-image"
"source_regurl_tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"target_regurl": "gcr.io/project-id/target-image"
}
}
```
Expand All @@ -96,10 +98,10 @@ master branch:

```json
{
"ref": "develop",
"ref": "master",
"inputs": {
"test-url-tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"prod-url": "gcr.io/project-id/target-image"
"source_regurl_tag": "gcr.io/project-id/source-image:2650c2f7c04640b8c67df560510914f7ba2033e2",
"target_regurl": "gcr.io/project-id/target-image"
}
}
```
Expand Down