From 1124cda8a7ae29d7805e31e42737f1d37d13c3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=ADdac=20Coll?= Date: Wed, 16 Nov 2022 12:05:18 +0100 Subject: [PATCH] feat: Move code from didix21/github-actions-orb to this repo - Change namespace didix21 to qustodio-github --- .circleci/config.yml | 1 + .circleci/test-deploy.yml | 20 +++++++++++++-- .github/ISSUE_TEMPLATE/BUG.yml | 2 +- .github/workflows/test-circleci-orb.yml | 17 +++++++++++++ src/@orb.yml | 12 +++------ src/commands/greet.yml | 15 ----------- src/commands/repository_dispatch.yml | 33 +++++++++++++++++++++++++ src/examples/example.yml | 26 +++++++++++++------ src/executors/default.yml | 12 --------- src/jobs/hello.yml | 14 ----------- src/scripts/greet.sh | 2 -- src/scripts/send-payload.sh | 24 ++++++++++++++++++ 12 files changed, 117 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/test-circleci-orb.yml delete mode 100755 src/commands/greet.yml create mode 100755 src/commands/repository_dispatch.yml mode change 100755 => 100644 src/examples/example.yml delete mode 100755 src/executors/default.yml delete mode 100755 src/jobs/hello.yml delete mode 100644 src/scripts/greet.sh create mode 100644 src/scripts/send-payload.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index de5bfe0..41ad441 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,7 @@ workflows: filters: *filters - orb-tools/review: filters: *filters + exclude: 'RC009' - shellcheck/check: filters: *filters - orb-tools/publish: diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index b213219..7c1faee 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -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 diff --git a/.github/ISSUE_TEMPLATE/BUG.yml b/.github/ISSUE_TEMPLATE/BUG.yml index 7959796..4538120 100644 --- a/.github/ISSUE_TEMPLATE/BUG.yml +++ b/.github/ISSUE_TEMPLATE/BUG.yml @@ -7,7 +7,7 @@ body: - type: checkboxes attributes: label: "Is there an existing issue for this?" - description: "Please search [here](https://github.com///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 diff --git a/.github/workflows/test-circleci-orb.yml b/.github/workflows/test-circleci-orb.yml new file mode 100644 index 0000000..95fcfc3 --- /dev/null +++ b/.github/workflows/test-circleci-orb.yml @@ -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 }}" + diff --git a/src/@orb.yml b/src/@orb.yml index d521371..001d94c 100755 --- a/src/@orb.yml +++ b/src/@orb.yml @@ -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/hello-build@0.0.5 diff --git a/src/commands/greet.yml b/src/commands/greet.yml deleted file mode 100755 index f4e2205..0000000 --- a/src/commands/greet.yml +++ /dev/null @@ -1,15 +0,0 @@ -description: > - This command echos "Hello World" using file inclusion. -# What will this command do? -# Descriptions should be short, simple, and clear. -parameters: - to: - type: string - default: "World" - description: "Hello to whom?" -steps: - - run: - environment: - PARAM_TO: <> - name: Hello Greeting - command: <> diff --git a/src/commands/repository_dispatch.yml b/src/commands/repository_dispatch.yml new file mode 100755 index 0000000..a39090e --- /dev/null +++ b/src/commands/repository_dispatch.yml @@ -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) >> diff --git a/src/examples/example.yml b/src/examples/example.yml old mode 100755 new mode 100644 index a2cdaab..5a13bf8 --- a/src/examples/example.yml +++ b/src/examples/example.yml @@ -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: - : /@1.2.3 + github-actions-orb: qustodio-github/github-actions-orb@v0.1.0 + + jobs: + say-hello-to-github: + docker: + - image: cimg/base:stable + steps: + - github-actions/repository_dispatch: + 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: - - / + - say-hello-to-github diff --git a/src/executors/default.yml b/src/executors/default.yml deleted file mode 100755 index ca3f5dc..0000000 --- a/src/executors/default.yml +++ /dev/null @@ -1,12 +0,0 @@ -description: > - This is a sample executor using Docker and Node. If you want to provide a custom environment in your orb, insert your image here. - If you do not require an executor, you can simply delete this directory. -docker: - - image: 'cimg/node:<>' -parameters: - tag: - default: lts - description: > - Pick a specific cimg/node image variant: - https://hub.docker.com/r/cimg/node/tags - type: string diff --git a/src/jobs/hello.yml b/src/jobs/hello.yml deleted file mode 100755 index 8f1df04..0000000 --- a/src/jobs/hello.yml +++ /dev/null @@ -1,14 +0,0 @@ -description: > - Sample description -# What will this job do? - -executor: default - -parameters: - to: - type: string - default: "World" - description: "Hello to whom?" -steps: - - greet: - to: << parameters.to >> diff --git a/src/scripts/greet.sh b/src/scripts/greet.sh deleted file mode 100644 index f01be79..0000000 --- a/src/scripts/greet.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo Hello "${PARAM_TO}" \ No newline at end of file diff --git a/src/scripts/send-payload.sh b/src/scripts/send-payload.sh new file mode 100644 index 0000000..a044f9c --- /dev/null +++ b/src/scripts/send-payload.sh @@ -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 \ No newline at end of file