diff --git a/README.md b/README.md index b8c9d58..6737b3f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![CodeQL](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/codeql.yml/badge.svg)](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/codeql.yml) [![ci](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/ci.yml/badge.svg)](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/ci.yml) +[![CodeQL](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/codeql.yml/badge.svg)](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/codeql.yml) [![ci](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/ci.yml/badge.svg)](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/ci.yml) -# GitHub Actions Reflector +# GitHub Actions Forwarder GitHub Actions workflow meant to run on [self-hosted](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) runners to leverage internal or private tooling (such as CICD systems) with GitHub repositories without the need to use reverse proxy implementations. Additionally could be used with [GitHub Larger Runners](https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners) with reserved IPs to minimize ingress points and remove the need for self-hosted runner administration and maintenance. @@ -14,7 +14,7 @@ The contents of this repository are individually maintained and are not a direct - `target-url`: **String**, **Required** - The target URL destination where webhook event payloads will be reflected to. + The target URL destination where webhook event payloads will be forwarded to. - `webhook-secret`: **String**, **Optional** Secret data value to use for webhook payload. Populates `X-Hub-Signature` and `X-Hub-Signature-256` header values. See [Securing Your Webhooks](https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks) for additional context. @@ -35,29 +35,29 @@ The contents of this repository are individually maintained and are not a direct ### Examples -Example simple workflow for consuming reflector: +Example simple workflow for consuming forwarder: ```yaml -name: reflector-call +name: forwarder-call on: pull_request: jobs: - reflector-call: + forwarder-call: runs-on: self-hosted steps: - - name: GitHub Actions Reflector - uses: collinmcneese/github-actions-reflector@main + - name: GitHub Actions Forwarder + uses: collinmcneese/github-actions-forwarder@v1 with: target-url: 'http://172.17.0.1:8080/github-webhook/' - webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET }} + webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET }} ``` Example workflow using [variables](https://docs.github.com/en/actions/learn-github-actions/variables) to target requests to different endpoints: ```yaml -name: reflector-dynamic +name: forwarder-dynamic on: pull_request: @@ -65,38 +65,38 @@ on: issues: jobs: - reflector-call: + forwarder-call: runs-on: self-hosted steps: - - name: Push - Reflector + - name: Push - Forwarder if: | github.event_name == 'push' || github.event_name == 'pull_request' - uses: collinmcneese/github-actions-reflector@main + uses: collinmcneese/github-actions-forwarder@v1 with: - target-url: ${{ vars.REFLECTOR_TARGET_PUSH }} - webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET_PUSH }} - allow-list-source: ${{ vars.REFLECTOR_ALLOW_LIST }} - - name: Issue - Reflector + target-url: ${{ vars.FORWARDER_TARGET_PUSH }} + webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET_PUSH }} + allow-list-source: ${{ vars.FORWARDER_ALLOW_LIST }} + - name: Issue - Forwarder if: ${{ github.event_name == 'issues' }} - uses: collinmcneese/github-actions-reflector@main + uses: collinmcneese/github-actions-forwarder@v1 with: - target-url: ${{ vars.REFLECTOR_TARGET_ISSUES }} - webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET_ISSUES }} - allow-list-source: ${{ vars.REFLECTOR_ALLOW_LIST }} + target-url: ${{ vars.FORWARDER_TARGET_ISSUES }} + webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET_ISSUES }} + allow-list-source: ${{ vars.FORWARDER_ALLOW_LIST }} ``` ## Why Does This Exist? -### Reflector Method +### Forwarder Method -Example overview of an implementation which uses the Actions Reflector workflow to route repository webhook events to internal systems. Actions Reflector is executed as a GitHub Actions workflow from `on:` events such as `push:` or `pull_request:` on self-hosted runners, routing event payloads to downstream target systems. This configuration leverages queueing, notification and retransmission capabilities of GitHub Actions and leverages self-hosted runners to prevent the need for ingress traffic initiation at a network edge. +Example overview of an implementation which uses the Actions Forwarder workflow to route repository webhook events to internal systems. Actions Forwarder is executed as a GitHub Actions workflow from `on:` events such as `push:` or `pull_request:` on self-hosted runners, routing event payloads to downstream target systems. This configuration leverages queueing, notification and retransmission capabilities of GitHub Actions and leverages self-hosted runners to prevent the need for ingress traffic initiation at a network edge. -reflector-setup +forwarder-setup --- -### Reverse Proxy Method (not Using Reflector) +### Reverse Proxy Method (not Using Forwarder) Example overview of an implementation which uses reverse proxy or an API gateway to allow webhook traffic from GitHub cloud repositories to internal systems. In this setup, webhook events are sent from github.com to a reverse proxy or API gateway which are routed to an internal CICD system. This example pattern becomes more complicated when adding additional reliability measures in place such as webhook notifications (success or failure), retransmissions and potentially a queueing mechanism at the API gateway layer to handle traffic bursts and scale as required. diff --git a/__test__/ci.sh b/__test__/ci.sh index 09a7a0a..4a46a14 100755 --- a/__test__/ci.sh +++ b/__test__/ci.sh @@ -4,7 +4,7 @@ # Wrapper function to run a command and capture the exit code function ci-run { - echo ":test_tube: $@" + echo "::Running: $@" $@ local status=$? if [ $status -ne 0 ]; then diff --git a/__test__/reflector.test.js b/__test__/forwarder.test.js similarity index 95% rename from __test__/reflector.test.js rename to __test__/forwarder.test.js index 1c1236b..a6e47a8 100644 --- a/__test__/reflector.test.js +++ b/__test__/forwarder.test.js @@ -1,7 +1,7 @@ -// Tests for functions in reflector.js +// Tests for functions in forwarder.js -const reflector = require('../src/reflector'); -const { validateUrl, fetchAllowListSource, validateAllowList, getWebhookSignature, getRequestOptions } = reflector.reflectorPrivate; +const forwarder = require('../src/forwarder'); +const { validateUrl, fetchAllowListSource, validateAllowList, getWebhookSignature, getRequestOptions } = forwarder.forwarderPrivate; let allowListObject = [ 'https://github.com', diff --git a/action.yml b/action.yml index ed69eb6..32205c0 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: GitHub Actions Reflector -description: Actions workflow for redirecting GitHub Actions event payloads to downstream applications. +name: GitHub Actions Forwarder +description: Actions workflow for forwarding GitHub Actions event payloads to downstream applications. author: 'Collin McNeese' branding: icon: 'fast-forward' diff --git a/dist/index.js b/dist/index.js index 3ea6e8e..fc24606 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42073,10 +42073,10 @@ function wrappy (fn, cb) { /***/ }), -/***/ 8917: +/***/ 2468: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { -// reflector.js +// forwarder.js const request = __nccwpck_require__(1265); const crypto = __nccwpck_require__(6113); @@ -42181,8 +42181,8 @@ function getRequestOptions(context, targetUrl, webhookSecret) { return options; } -// Main Reflector function -async function reflector({context, targetUrl, webhookSecret, allowListSource}) { +// Main Forwarder function +async function forwarder({context, targetUrl, webhookSecret, allowListSource}) { // Validate that targetUrl is a valid URL validateUrl(targetUrl); @@ -42215,7 +42215,7 @@ async function reflector({context, targetUrl, webhookSecret, allowListSource}) { }; // Export private functions for testing -const reflectorPrivate = { +const forwarderPrivate = { validateUrl, fetchAllowListSource, validateAllowList, @@ -42224,8 +42224,8 @@ const reflectorPrivate = { }; module.exports = { - reflectorPrivate, - reflector, + forwarderPrivate, + forwarder, }; @@ -42612,15 +42612,15 @@ var __webpack_exports__ = {}; const core = __nccwpck_require__(9991); const github = __nccwpck_require__(6140); -const { reflector } = __nccwpck_require__(8917); +const { forwarder } = __nccwpck_require__(2468); // Parse inputs const targetUrl = core.getInput('target-url'); const webhookSecret = core.getInput('webhook-secret'); const allowListSource = core.getInput('allow-list-source'); -// Run the Reflector action -reflector({ +// Run the Forwarder action +forwarder({ context: github.context, targetUrl: targetUrl, webhookSecret: webhookSecret, diff --git a/docs/010.png b/docs/010.png index 0666931..840b514 100644 Binary files a/docs/010.png and b/docs/010.png differ diff --git a/package-lock.json b/package-lock.json index 31430b5..d01fde3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "github-actions-reflector", + "name": "github-actions-forwarder", "version": "0.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "github-actions-reflector", + "name": "github-actions-forwarder", "version": "0.4.0", "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index a3ab46c..6fe8206 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "github-actions-reflector", + "name": "github-actions-forwarder", "version": "1.0.0", "description": "Workflow for redirecting GitHub Actions event payloads to downstream applications", "main": "src/index.js", @@ -13,7 +13,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/collinmcneese/github-actions-reflector.git" + "url": "git+https://github.com/collinmcneese/github-actions-forwarder.git" }, "keywords": [ "github", @@ -22,9 +22,9 @@ "author": "Collin McNeese ", "license": "MIT", "bugs": { - "url": "https://github.com/collinmcneese/github-actions-reflector/issues" + "url": "https://github.com/collinmcneese/github-actions-forwarder/issues" }, - "homepage": "https://github.com/collinmcneese/github-actions-reflector#readme", + "homepage": "https://github.com/collinmcneese/github-actions-forwarder#readme", "devDependencies": { "cspell": "^6.19.2", "eslint": "^8.32.0", diff --git a/src/reflector.js b/src/forwarder.js similarity index 96% rename from src/reflector.js rename to src/forwarder.js index 839f503..521c5f8 100644 --- a/src/reflector.js +++ b/src/forwarder.js @@ -1,4 +1,4 @@ -// reflector.js +// forwarder.js const request = require('request'); const crypto = require('crypto'); @@ -103,8 +103,8 @@ function getRequestOptions(context, targetUrl, webhookSecret) { return options; } -// Main Reflector function -async function reflector({context, targetUrl, webhookSecret, allowListSource}) { +// Main Forwarder function +async function forwarder({context, targetUrl, webhookSecret, allowListSource}) { // Validate that targetUrl is a valid URL validateUrl(targetUrl); @@ -137,7 +137,7 @@ async function reflector({context, targetUrl, webhookSecret, allowListSource}) { }; // Export private functions for testing -const reflectorPrivate = { +const forwarderPrivate = { validateUrl, fetchAllowListSource, validateAllowList, @@ -146,6 +146,6 @@ const reflectorPrivate = { }; module.exports = { - reflectorPrivate, - reflector, + forwarderPrivate, + forwarder, }; diff --git a/src/index.js b/src/index.js index 8965386..249ab85 100644 --- a/src/index.js +++ b/src/index.js @@ -2,15 +2,15 @@ const core = require('@actions/core'); const github = require('@actions/github'); -const { reflector } = require('./reflector'); +const { forwarder } = require('./forwarder'); // Parse inputs const targetUrl = core.getInput('target-url'); const webhookSecret = core.getInput('webhook-secret'); const allowListSource = core.getInput('allow-list-source'); -// Run the Reflector action -reflector({ +// Run the Forwarder action +forwarder({ context: github.context, targetUrl: targetUrl, webhookSecret: webhookSecret,