Skip to content

Commit

Permalink
feat: Move code from didix21/github-actions-orb to this repo
Browse files Browse the repository at this point in the history
- Change namespace didix21 to qustodio-github
  • Loading branch information
didix21 committed Nov 16, 2022
1 parent 54eb025 commit 1124cda
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 61 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workflows:
filters: *filters
- orb-tools/review:
filters: *filters
exclude: 'RC009'
- shellcheck/check:
filters: *filters
- orb-tools/publish:
Expand Down
20 changes: 18 additions & 2 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@ jobs:
- image: cimg/base:current
steps:
- checkout
# Run your orb's commands to validate them.
- github-actions-orb/greet
# Implement your tests here
- run:
name: 'Check token'
command: echo $P_GITHUB_TOKEN
# Check repostiroy_dispatch works providing all parameters
- github-actions-orb/repository_dispatch:
repo_name: "qustodio/github-actions-orb" # Your GitHub organization name + repo name
event_type: "build_finished" # Arbitrary string that your GitHub Actions will filter on
github_personal_access_token: P_GITHUB_TOKEN
metadata: '{"version": "0.1.0"}'
# Metadata should be optional
- github-actions-orb/repository_dispatch:
repo_name: "qustodio/github-actions-orb" # Your GitHub organization name + repo name
event_type: "metadata_is_optional" # Arbitrary string that your GitHub Actions will filter on
github_personal_access_token: P_GITHUB_TOKEN


workflows:
test-deploy:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
- command-tests:
context: orb-publishing
filters: *filters
- orb-tools/pack:
filters: *filters
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body:
- type: checkboxes
attributes:
label: "Is there an existing issue for this?"
description: "Please search [here](https://github.com/<organization>/<project-name>/issues?q=is%3Aissue) to see if an issue already exists for the bug you encountered"
description: "Please search [here](https://github.com/qustodio/github-actions-orb/issues) to see if an issue already exists for the bug you encountered"
options:
- label: "I have searched the existing issues"
required: true
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/test-circleci-orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Test CircleCI Orb"

on:
repository_dispatch:
types: [build_finished]

jobs:
build_finished:
runs-on: ubuntu-latest
steps:
- run: |
echo "Buld number: ${{ github.event.client_payload.build_num }}"
echo "Build url: ${{ github.event.client_payload.build_url }}"
echo "Build commit: ${{ github.event.client_payload.vcs_revision }}"
echo "Build metadata: ${{ github.event.client_payload.metadata }}"
echo "Version provided by metadata: ${{ fromJSON(github.event.client_payload.metadata).version }}"
12 changes: 4 additions & 8 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
version: 2.1

description: >
Sample orb description
# What will your orb allow users to accomplish?
# Descriptions should be short, simple, and informative.
Interact with GitHub Actions from CircleCI. In other words, this orbs
triggers a repository_dispatch event within GitHub Actions for the desired repo,
sending a default payload.
# This information will be displayed in the orb registry and is not mandatory.
display:
home_url: "https://www.example.com/docs"
home_url: "https://github.com/qustodio/github-actions-orb"
source_url: "https://github.com/qustodio/github-actions-orb"

# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
# orbs:
# hello: circleci/[email protected]
15 changes: 0 additions & 15 deletions src/commands/greet.yml

This file was deleted.

33 changes: 33 additions & 0 deletions src/commands/repository_dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
description: >
Triggers a repository_dispatch event within GitHub Actions for the desired repo.
event_type, repo_name and github_personal_access_token fields must be provided.
parameters:
repo_name:
type: string
description: "The organization and repo name to trigger the event for (ex. `qustodio/hello-world`)"
event_type:
type: string
description: "The ['event_type'](https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-a-repository-dispatch-event) parameter to send"
github_personal_access_token:
type: env_var_name
description: "The environment variable name containing a GitHub 'Personal Access Token' (PAT) with the `repo` scope"
metadata:
type: string
description: "Send any payload through this field. For example: `{'version': '0.1.0'}`"
default: "null"

steps:
- run:
name: "Set enviroment variables"
command: |
echo 'export PRIVATE_GH_TOKEN=$(echo $<< parameters.github_personal_access_token >>)' >> "$BASH_ENV"
source "$BASH_ENV"
- run:
environment:
- REPO_NAME: << parameters.repo_name >>
- EVENT_TYPE: << parameters.event_type >>
- METADATA: << parameters.metadata >>
when: always
name: Bundle build info into webhook payload
command: << include(scripts/send-payload.sh) >>
26 changes: 19 additions & 7 deletions src/examples/example.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
description: >
Sample example description.
# Provide a use-case based example for using this orb.
# Everything in the `usage` section will be displayed in the orb registry.
# Comments are not retained.
This is an example on how to use github-actions-orb on CircleCI.
Providing some extra metadata and the event_type.
usage:
version: 2.1
orbs:
<orb-name>: <namespace>/<orb-name>@1.2.3
github-actions-orb: qustodio-github/[email protected]

jobs:
say-hello-to-github:
docker:
- image: cimg/base:stable
steps:
- github-actions/repository_dispatch:
repo_name: "<user>/<your-repo-name>" # Your GitHub organization name + repo name
event_type: "build_finished" # Arbitrary string that your GitHub Actions will filter on
github_personal_access_token: "GITHUB_PERSONAL_TOKEN"
metadata: '{"version": "0.1.0"}'

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
use-my-orb:
release:
jobs:
- <orb-name>/<job-name>
- say-hello-to-github
12 changes: 0 additions & 12 deletions src/executors/default.yml

This file was deleted.

14 changes: 0 additions & 14 deletions src/jobs/hello.yml

This file was deleted.

2 changes: 0 additions & 2 deletions src/scripts/greet.sh

This file was deleted.

24 changes: 24 additions & 0 deletions src/scripts/send-payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
OUTPUT=$(echo '{}' | jq '{
"event_type": env.EVENT_TYPE,
"client_payload": {
"build_num": env.CIRCLE_BUILD_NUM,
"branch": env.CIRCLE_BRANCH,
"username": env.CIRCLE_USERNAME,
"job": env.CIRCLE_JOB,
"build_url": env.CIRCLE_BUILD_URL,
"vcs_revision": env.CIRCLE_SHA1,
"reponame": env.CIRCLE_PROJECT_REPONAME,
"workflow_id": env.CIRCLE_WORKFLOW_ID,
"pull_request": env.CI_PULL_REQUEST,
"metadata": env.METADATA,
}
}' | curl -X POST -H "Content-Type:application/json" -H "Accept:application/vnd.github.v3+json" -H "Authorization: token $PRIVATE_GH_TOKEN" -d @- "https://api.github.com/repos/${REPO_NAME}/dispatches")

echo "$OUTPUT"

if [[ -z $OUTPUT ]]; then
exit 0;
else
exit 1;
fi

0 comments on commit 1124cda

Please sign in to comment.