├── .prettierignore ├── .gitattributes ├── .release-please-manifest.json ├── .eslintignore ├── docs └── assets │ ├── custom-parameters.png │ ├── message-attributes.png │ └── spinnaker-automated-trigger.png ├── .prettierrc.json ├── .github ├── dependabot.yml ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ ├── publish.yaml │ ├── codeql-analysis.yml │ ├── release.yaml │ └── test.yaml └── config.yml ├── .nyrc.json ├── release-please-config.json ├── .editorconfig ├── jest.config.js ├── src ├── index.ts └── main.ts ├── action.yml ├── tsconfig.json ├── CONTRIBUTING.md ├── .gitignore ├── package.json ├── .eslintrc.json ├── CHANGELOG.md ├── CODE-OF-CONDUCT.md ├── README.md ├── __tests__ └── main.test.ts └── LICENSE /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | lib/ 3 | node_modules/ 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | dist/** -diff linguist-generated=true 2 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "1.2.1" 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | lib/ 3 | node_modules/ 4 | jest.config.js 5 | -------------------------------------------------------------------------------- /docs/assets/custom-parameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExpediaGroup/spinnaker-pipeline-trigger/HEAD/docs/assets/custom-parameters.png -------------------------------------------------------------------------------- /docs/assets/message-attributes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExpediaGroup/spinnaker-pipeline-trigger/HEAD/docs/assets/message-attributes.png -------------------------------------------------------------------------------- /docs/assets/spinnaker-automated-trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ExpediaGroup/spinnaker-pipeline-trigger/HEAD/docs/assets/spinnaker-automated-trigger.png -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": false, 6 | "singleQuote": true, 7 | "trailingComma": "none", 8 | "bracketSpacing": true, 9 | "arrowParens": "avoid" 10 | } 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | commit-message: 8 | prefix: "chore(deps):" 9 | prefix-development: "build(deps):" 10 | - package-ecosystem: "github-actions" 11 | directory: "/" 12 | schedule: 13 | interval: "daily" 14 | -------------------------------------------------------------------------------- /.nyrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@istanbuljs/nyc-config-typescript", 3 | "include": [ 4 | "src/**/*.ts" 5 | ], 6 | "exclude": [ 7 | "node_modules/" 8 | ], 9 | "extension": [ 10 | ".ts" 11 | ], 12 | "reporter": [ 13 | "text-summary", 14 | "html" 15 | ], 16 | "report-dir": "./coverage" 17 | } 18 | -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": { 3 | ".": { 4 | "changelog-path": "CHANGELOG.md", 5 | "release-type": "simple", 6 | "bump-minor-pre-major": false, 7 | "bump-patch-for-minor-pre-major": false, 8 | "draft": false, 9 | "prerelease": false 10 | } 11 | }, 12 | "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" 13 | } 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | charset = utf-8 11 | end_of_line = lf 12 | 13 | [*.{yaml,yml}] 14 | indent_size = 2 15 | 16 | [*.{ts,js}] 17 | indent_size = 2 18 | 19 | [*.bat] 20 | indent_style = tab 21 | end_of_line = crlf 22 | 23 | [LICENSE] 24 | insert_final_newline = false 25 | 26 | [Makefile] 27 | indent_style = tab 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 12 | 13 | ### :pencil: Description 14 | 15 | 16 | ### :link: Related Issues 17 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/__tests__/*.test.ts'], 6 | testRunner: 'jest-circus/runner', 7 | transform: { 8 | '^.+\\.ts$': 'ts-jest' 9 | }, 10 | verbose: true, 11 | collectCoverage: true, 12 | collectCoverageFrom: ['src/**/*.{ts,js,jsx}'], 13 | coverageThreshold: { 14 | global: { 15 | branches: 90, 16 | functions: 90, 17 | lines: 90, 18 | statements: 90 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Expedia, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | https://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { run } from './main' 18 | 19 | run() 20 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "spinnaker-pipeline-trigger" 3 | description: "Triggers Spinnaker pipelines using AWS SNS" 4 | author: "ExpediaGroup" 5 | inputs: 6 | topic_arn: 7 | description: Topic ARN 8 | required: true 9 | parameters: 10 | description: Parameters passed to pipeline execution. 11 | required: false 12 | message_attributes: 13 | description: Message attributes passed to pipeline execution. 14 | required: false 15 | aws_region: 16 | description: AWS Region 17 | required: false 18 | default: us-west-2 19 | github_token: 20 | description: Repo token for fetching commit details 21 | required: false 22 | runs: 23 | using: "node16" 24 | main: "dist/index.js" 25 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Publish 3 | 4 | on: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: Update Major Version 13 | run: | 14 | MAJOR_VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3 | cut -d "." -f1) 15 | echo "New version: ${MAJOR_VERSION}" 16 | git tag -f ${MAJOR_VERSION} 17 | git push --tags -f 18 | build: # make sure build/ci work properly 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v3 22 | with: 23 | ref: ${{ github.event.pull_request.head.ref }} 24 | - uses: actions/setup-node@v3 25 | with: 26 | node-version: "16" 27 | - run: | 28 | yarn 29 | - run: | 30 | yarn all 31 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "CodeQL" 3 | 4 | on: 5 | push: 6 | branches: [ main ] 7 | pull_request: 8 | # The branches below must be a subset of the branches above 9 | branches: [ main ] 10 | schedule: 11 | - cron: '17 8 * * 6' 12 | 13 | jobs: 14 | analyze: 15 | name: Analyze 16 | runs-on: ubuntu-latest 17 | permissions: 18 | actions: read 19 | contents: read 20 | security-events: write 21 | 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | language: [ 'javascript' ] 26 | 27 | steps: 28 | - name: Checkout repository 29 | uses: actions/checkout@v3 30 | 31 | # Initializes the CodeQL tools for scanning. 32 | - name: Initialize CodeQL 33 | uses: github/codeql-action/init@v2 34 | with: 35 | languages: ${{ matrix.language }} 36 | 37 | - name: Autobuild 38 | uses: github/codeql-action/autobuild@v2 39 | 40 | - name: Perform CodeQL Analysis 41 | uses: github/codeql-action/analyze@v2 42 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: 9 | actions: write 10 | contents: write 11 | pull-requests: write 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - id: release 18 | name: Run release please 19 | uses: google-github-actions/release-please-action@v3 20 | with: 21 | command: manifest 22 | - if: steps.release.outputs.releases_created 23 | name: Trigger Publish 24 | uses: actions/github-script@v6 25 | with: 26 | github-token: ${{ (secrets.github-token != '' && secrets.github-token) || secrets.GITHUB_TOKEN }} 27 | retries: 3 28 | script: | 29 | github.rest.actions.createWorkflowDispatch({ 30 | owner: context.repo.owner, 31 | repo: context.repo.repo, 32 | workflow_id: 'publish.yaml', 33 | ref: '${{ steps.release.outputs.tag_name }}' 34 | }) 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 4 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 5 | "outDir": "./lib", /* Redirect output structure to the directory. */ 6 | //"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 7 | "strict": true, /* Enable all strict type-checking options. */ 8 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 9 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 10 | "sourceMap": true, 11 | "moduleResolution": "node" 12 | }, 13 | "exclude": [ 14 | "node_modules", 15 | "**/*.test.ts", 16 | "**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | title: "[Bug]: " 4 | labels: [bug, triage] 5 | assignees: 6 | - mcaulifn 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thanks for taking the time to fill out this bug report! 12 | - type: textarea 13 | id: actual 14 | attributes: 15 | label: What happened? 16 | description: Please describe the actual outcome. Include a link to the workflow run if possible. 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: expected 21 | attributes: 22 | label: What was expected? 23 | description: Please describe what was expected to happen. 24 | validations: 25 | required: false 26 | - type: textarea 27 | id: config 28 | attributes: 29 | label: Workflow config 30 | description: Please include workflow config that generated the issue. 31 | validations: 32 | required: true 33 | - type: textarea 34 | id: logs 35 | attributes: 36 | label: Relevant log output 37 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 38 | render: shell 39 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Test" 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | test: # make sure build/ci work properly 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | with: 14 | fetch-depth: 0 15 | ref: ${{github.event.pull_request.head.ref}} 16 | repository: ${{github.event.pull_request.head.repo.full_name}} 17 | - uses: actions/setup-node@v3 18 | with: 19 | node-version: "16" 20 | - run: | 21 | yarn 22 | - run: | 23 | yarn all 24 | - name: Check for diff 25 | id: diff 26 | run: | 27 | if git status -s dist/ | grep "dist/"; then 28 | echo "SHOULD_PUSH_BUILD=true" >> "$GITHUB_OUTPUT" 29 | else 30 | echo "SHOULD_PUSH_BUILD=false" >> "$GITHUB_OUTPUT" 31 | fi 32 | 33 | - name: Push build 34 | if: ${{ steps.diff.outputs.SHOULD_PUSH_BUILD == 'true' }} 35 | run: | 36 | git config user.name github-actions 37 | git config user.email github-actions@github.com 38 | git add dist/* 39 | git commit -m "chore: Build Source" 40 | git push 41 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your patches and contributions to this project. There are just a few guidelines you need to follow which are described in detail below. 4 | 5 | ## How To Contribute 6 | 7 | ### 1. Fork this repo 8 | 9 | You should create a fork of this project in your account and work from there. You can create a fork by clicking the fork button in GitHub. 10 | 11 | ### 2. One feature, one branch 12 | 13 | Work for each new feature/issue should occur in its own branch. To create a new branch from the command line: 14 | 15 | ```shell 16 | git checkout -b my-new-feature 17 | ``` 18 | 19 | where "my-new-feature" describes what you're working on. 20 | 21 | ### 3. Add tests for any bug fixes or new functionality 22 | 23 | ### 4. Check code style 24 | 25 | Before opening a pull request, ensure that your new code conforms to the code style as defined by the [EditorConfig](https://editorconfig.org/) file in the root of the project. 26 | 27 | ### 5. Add documentation for new or updated functionality 28 | 29 | Please review all of the .md files in this project to see if they are impacted by your change and update them accordingly. 30 | 31 | ### 6. Format Commits 32 | 33 | This project uses [Semantic Release](https://github.com/semantic-release/semantic-release) for versioning. As such, commits need to follow the format: `(): `. All fields are required. 34 | 35 | ### 7. Submit Pull Request and describe the change 36 | 37 | Push your changes to your branch and open a pull request against the parent repo on GitHub. The project administrators will review your pull request and respond with feedback. 38 | 39 | ## How Your Contribution Gets Merged 40 | 41 | Upon Pull Request submission, your code will be reviewed by the maintainers. They will confirm at least the following: 42 | 43 | - Tests run successfully (unit, coverage, integration, style). 44 | - Contribution policy has been followed. 45 | 46 | Two (human) reviewers will need to sign off on your Pull Request before it can be merged. 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directory 2 | node_modules 3 | 4 | # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed 20 | *.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | *.lcov 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variables file 69 | .env 70 | .env.test 71 | 72 | # parcel-bundler cache (https://parceljs.org/) 73 | .cache 74 | 75 | # next.js build output 76 | .next 77 | 78 | # nuxt.js build output 79 | .nuxt 80 | 81 | # vuepress build output 82 | .vuepress/dist 83 | 84 | # Serverless directories 85 | .serverless/ 86 | 87 | # FuseBox cache 88 | .fusebox/ 89 | 90 | # DynamoDB Local files 91 | .dynamodb/ 92 | 93 | # OS metadata 94 | .DS_Store 95 | Thumbs.db 96 | 97 | # Ignore built ts files 98 | __tests__/runner/* 99 | lib/**/* 100 | 101 | .vscode 102 | 103 | src/**/*.js 104 | src/**/*.map 105 | 106 | lib/ 107 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spinnaker-pipeline-trigger", 3 | "version": "0.0.0", 4 | "private": true, 5 | "description": "TypeScript template action", 6 | "main": "lib/index.js", 7 | "scripts": { 8 | "build": "tsc", 9 | "build:watch": "onchange 'src/**/*.ts' -- yarn run build", 10 | "clean": "rm -rf coverage src/**/*.js src/**/*.map", 11 | "format": "prettier --write **/*.ts", 12 | "format-check": "prettier --check **/*.ts", 13 | "lint": "eslint src/**/*.ts", 14 | "package": "ncc build --source-map --no-source-map-register --license licenses.txt", 15 | "start": "ts-node src/index.ts", 16 | "test": "jest --coverage", 17 | "test:watch": "jest --coverage --watchAll", 18 | "view:coverage": "serve coverage/lcov-report", 19 | "all": "yarn build && yarn format && yarn lint && yarn package && yarn test" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/ExpediaGroup/spinnaker-pipeline-trigger.git" 24 | }, 25 | "keywords": [ 26 | "actions", 27 | "node", 28 | "setup" 29 | ], 30 | "author": "Expedia Group ", 31 | "license": "MIT", 32 | "dependencies": { 33 | "@actions/core": "1.10.0", 34 | "@actions/github": "^5.1.1", 35 | "@aws-sdk/client-sns": "3.395.0", 36 | "@types/js-yaml": "^4.0.5", 37 | "@types/node": "20.5.4", 38 | "js-yaml": "^4.1.0" 39 | }, 40 | "devDependencies": { 41 | "@types/jest": "27.4.1", 42 | "@types/mock-fs": "4.13.1", 43 | "@types/source-map-support": "0.5.6", 44 | "@typescript-eslint/eslint-plugin": "4.33.0", 45 | "@typescript-eslint/parser": "4.33.0", 46 | "@vercel/ncc": "0.36.1", 47 | "eslint": "7.32.0", 48 | "eslint-plugin-github": "4.1.5", 49 | "eslint-plugin-jest": "27.2.3", 50 | "eslint-plugin-prettier": "4.2.1", 51 | "jest": "27.5.1", 52 | "jest-circus": "27.5.1", 53 | "mock-fs": "5.2.0", 54 | "nyc": "15.1.0", 55 | "onchange": "7.1.0", 56 | "prettier": "2.8.8", 57 | "serve": "14.2.1", 58 | "source-map-support": "0.5.21", 59 | "ts-jest": "27.1.3", 60 | "ts-mockito": "2.6.1", 61 | "ts-node": "10.9.1", 62 | "typescript": "4.9.5" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "jest", 4 | "@typescript-eslint" 5 | ], 6 | "extends": [ 7 | "plugin:github/recommended" 8 | ], 9 | "parser": "@typescript-eslint/parser", 10 | "parserOptions": { 11 | "ecmaVersion": 9, 12 | "sourceType": "module", 13 | "project": "./tsconfig.json" 14 | }, 15 | "rules": { 16 | "eslint-comments/no-use": "off", 17 | "import/no-namespace": "off", 18 | "no-unused-vars": "off", 19 | "@typescript-eslint/no-unused-vars": "error", 20 | "@typescript-eslint/explicit-member-accessibility": [ 21 | "error", 22 | { 23 | "accessibility": "no-public" 24 | } 25 | ], 26 | "@typescript-eslint/no-require-imports": "error", 27 | "@typescript-eslint/array-type": "error", 28 | "@typescript-eslint/await-thenable": "error", 29 | "@typescript-eslint/ban-ts-comment": "error", 30 | "camelcase": "off", 31 | "@typescript-eslint/consistent-type-assertions": "error", 32 | "@typescript-eslint/explicit-function-return-type": [ 33 | "error", 34 | { 35 | "allowExpressions": true 36 | } 37 | ], 38 | "@typescript-eslint/func-call-spacing": [ 39 | "error", 40 | "never" 41 | ], 42 | "@typescript-eslint/no-array-constructor": "error", 43 | "@typescript-eslint/no-empty-interface": "error", 44 | "@typescript-eslint/no-explicit-any": "error", 45 | "@typescript-eslint/no-extraneous-class": "error", 46 | "@typescript-eslint/no-for-in-array": "error", 47 | "@typescript-eslint/no-inferrable-types": "error", 48 | "@typescript-eslint/no-misused-new": "error", 49 | "@typescript-eslint/no-namespace": "error", 50 | "@typescript-eslint/no-non-null-assertion": "warn", 51 | "@typescript-eslint/no-unnecessary-qualifier": "error", 52 | "@typescript-eslint/no-unnecessary-type-assertion": "error", 53 | "@typescript-eslint/no-useless-constructor": "error", 54 | "@typescript-eslint/no-var-requires": "error", 55 | "@typescript-eslint/prefer-for-of": "warn", 56 | "@typescript-eslint/prefer-function-type": "warn", 57 | "@typescript-eslint/prefer-includes": "error", 58 | "@typescript-eslint/prefer-string-starts-ends-with": "error", 59 | "@typescript-eslint/promise-function-async": "error", 60 | "@typescript-eslint/require-array-sort-compare": "error", 61 | "@typescript-eslint/restrict-plus-operands": "error", 62 | "semi": "off", 63 | "@typescript-eslint/semi": [ 64 | "error", 65 | "never" 66 | ], 67 | "@typescript-eslint/type-annotation-spacing": "error", 68 | "@typescript-eslint/unbound-method": "error" 69 | }, 70 | "env": { 71 | "node": true, 72 | "es6": true, 73 | "jest/globals": true 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.2.1](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/compare/v1.2.0...v1.2.1) (2023-08-29) 4 | 5 | 6 | ### Bug Fixes 7 | 8 | * Fix test workflow to not error if grep fails ([dd0fa89](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/dd0fa8923b7d816720eaca60e942c75e25c10784)) 9 | * forgot the end parenthesis ([8fd1d82](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/8fd1d82ac6a6d15102b3bb850dcb70dcb01e53c9)) 10 | * forgot to add new input to action.yml ([bba71f8](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/bba71f838904d84b35452c0537d7c5328f0e370c)) 11 | * just use an if statement ([9e43082](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/9e43082d9a27f2e0857240573116701ee2e3e198)) 12 | * Remove [] operator from if statement ([29002db](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/29002db31c4ad9da85f88e087760d6ae1e904da7)) 13 | 14 | ## [1.2.0](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/compare/v1.1.2...v1.2.0) (2023-08-28) 15 | 16 | 17 | ### Features 18 | 19 | * **artifacts:** Add support for trigger artifacts ([#430](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/430)) ([2d2f763](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/2d2f76390f418ff618d4db6a1308d3ca7b671ec8)) 20 | 21 | ## [1.1.2](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/compare/v1.1.1...v1.1.2) (2023-08-24) 22 | 23 | 24 | ### Bug Fixes 25 | 26 | * **ci:** Correct output syntax ([#432](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/432)) ([976d212](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/976d212e4c6b7ac0c0d2eedfdbf5239d7ff1d551)) 27 | * **deps:** bump @types/node from 20.5.3 to 20.5.4 ([#427](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/427)) ([adcf6e5](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/adcf6e5e668964770bffaf8fabe4a855aad46af1)) 28 | 29 | ## [1.1.1](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/compare/v1.1.0...v1.1.1) (2023-08-23) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * **deps:** bump @aws-sdk/client-sns from 3.160.0 to 3.395.0 ([#415](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/415)) ([869c720](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/869c720546fb51bfceeab43ee9e9e8c24fa13de3)) 35 | 36 | ## [1.1.0](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/compare/v1.0.3...v1.1.0) (2023-08-22) 37 | 38 | 39 | ### Features 40 | 41 | * **runtime:** Update to Node 16 ([#284](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/284)) ([7b067d8](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/7b067d805755b901cce1bad5b2fbb2f03222faa2)) 42 | 43 | 44 | ### Bug Fixes 45 | 46 | * **deps:** bump json5 from 2.2.0 to 2.2.3 ([#328](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/328)) ([5519b1a](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/5519b1ac33dc35043abf9083b7dcebdfa05082b6)) 47 | * **release:** Use release-please ([#418](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/issues/418)) ([f897777](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/commit/f89777752a4222634a4531261b8de201eff92992)) 48 | -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behaviour that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behaviour by participants include: 24 | 25 | * The use of sexualised language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behaviour and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behaviour. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviours that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behaviour may be 58 | reported by contacting [the project team](oss@expediagroup.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Expedia, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | https://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import * as core from '@actions/core' 18 | import * as github from '@actions/github' 19 | import * as yaml from 'js-yaml' 20 | import { 21 | PublishCommand, 22 | PublishInput, 23 | SNSServiceException, 24 | SNSClient 25 | } from '@aws-sdk/client-sns' 26 | 27 | const SNS_MESSAGE_SIZE_LIMIT_BYTES = 256000 28 | 29 | interface GitHubFile { 30 | filename: string 31 | status: string 32 | } 33 | 34 | async function publish( 35 | message: object, 36 | topicArn: string, 37 | region: string 38 | ): Promise { 39 | const messageString = JSON.stringify(message) 40 | core.debug(messageString) 41 | const input: PublishInput = { 42 | Message: messageString, 43 | TopicArn: topicArn 44 | } 45 | 46 | const config = { region } 47 | 48 | const client = new SNSClient(config) 49 | const command = new PublishCommand(input) 50 | const response = await client.send(command) 51 | 52 | core.debug(JSON.stringify(response.MessageId)) 53 | return JSON.stringify(response.MessageId) 54 | } 55 | 56 | async function constructMessage(): Promise { 57 | const repository = process.env.GITHUB_REPOSITORY 58 | const commit = process.env.GITHUB_SHA 59 | const githubApiUrl = process.env.GITHUB_API_URL 60 | const ref = process.env.GITHUB_REF || '' 61 | const githubAction = process.env.GITHUB_ACTION || '' 62 | const githubEventName = process.env.GITHUB_EVENT_NAME || '' 63 | const githubActor = process.env.GITHUB_ACTOR || '' 64 | const parameters = yaml.load(core.getInput('parameters')) || {} 65 | const messageAttributes = core.getInput('message_attributes') || '' 66 | const modifiedFiles = await getModifiedFiles() 67 | 68 | const message = { 69 | repository, 70 | commit, 71 | githubApiUrl, 72 | ref, 73 | githubEventName, 74 | githubActor, 75 | githubAction, 76 | parameters, 77 | messageAttributes, 78 | modifiedFiles 79 | } 80 | 81 | // SNS message size limit is 256 KB 82 | if ( 83 | Buffer.byteLength(JSON.stringify(message)) > SNS_MESSAGE_SIZE_LIMIT_BYTES 84 | ) { 85 | core.warning( 86 | 'SNS message size limit exceeded, removing modifiedFiles from message' 87 | ) 88 | message.modifiedFiles = [] 89 | } 90 | 91 | return message 92 | } 93 | 94 | async function getModifiedFiles(): Promise { 95 | const token = core.getInput('github_token') 96 | if (!token) { 97 | core.debug( 98 | 'No github token provided, defaulting to empty list of modified files' 99 | ) 100 | return [] 101 | } 102 | const octokit = github.getOctokit(token) 103 | const { data } = await octokit.rest.repos.getCommit({ 104 | owner: github.context.repo.owner, 105 | repo: github.context.repo.repo, 106 | ref: github.context.sha 107 | }) 108 | if (!data.files) { 109 | core.debug('No files found in getCommit response') 110 | return [] 111 | } 112 | const files = data.files 113 | .filter((file: GitHubFile) => file.status !== 'removed') 114 | .map((file: GitHubFile) => file.filename) 115 | core.debug(`Found ${files.length} changed files`) 116 | return files 117 | } 118 | 119 | export async function run(): Promise { 120 | core.info('Spinnaker Pipeline Trigger :shipit:') 121 | 122 | const topicArn = core.getInput('topic_arn') 123 | const region = core.getInput('aws_region') || 'us-west-2' 124 | 125 | try { 126 | if (!topicArn) { 127 | throw new Error('Topic ARN is required.') 128 | } 129 | const message = await constructMessage() 130 | core.debug(JSON.stringify(message)) 131 | await publish(message, topicArn, region) 132 | } catch (error) { 133 | if (error instanceof SNSServiceException) core.warning(error.message) 134 | core.setFailed('Failed to publish message.') 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spinnaker-pipeline-trigger 2 | 3 | Trigger Spinnaker pipelines from Actions 4 | 5 | ![Build](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/workflows/Publish/badge.svg) 6 | ![Release](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/workflows/Release/badge.svg) 7 | 8 | ## Usage 9 | 10 | Include `ExpediaGroup/spinnaker-pipeline-trigger` as final step in workflow to trigger Spinnaker. 11 | 12 | ### Basic 13 | 14 | ```yaml 15 | steps: 16 | - name: Spinnaker 17 | uses: ExpediaGroup/spinnaker-pipeline-trigger@v1 18 | with: 19 | github_token: ${{ secrets.GITHUB_TOKEN }} 20 | topic_arn: ${{ secrets.SPINNAKER_TOPIC_ARN }} 21 | ``` 22 | 23 | Configure the pipeline trigger as example below, adjusting the `Payload Constraints` as needed: 24 | 25 | * `repository`: the `org/repo` repository key. 26 | * `ref`: match the ref used to trigger the workflow. Ex. `main` if the ref is for a merge to the main branch or `refs/tags/*` for when a new tag is created. 27 | 28 | NOTE: The `Payload Constraints` fields are regex values. To only include a specific `repository`, `ref`, or other constraint, be specific. Example: `^AwesomeOrg/awesome-repo$` to include ONLY that repository. 29 | 30 | ![Spinnaker Automated Trigger](docs/assets/spinnaker-automated-trigger.png) 31 | 32 | ### Default Parameters 33 | 34 | The action sends the following information in the payload: 35 | 36 | * repository: The owner and repository name. For example, `octocat/Hello-World`. 37 | * commit: The commit SHA that triggered the workflow. For example, `ffac537e6cbbf934b08745a378932722df287a53`. 38 | * ref: The branch or tag ref that triggered the workflow. For example, `refs/heads/feature-branch-1`. If neither a branch or tag is available for the event type, the variable will not exist. 39 | * githubEventName: The name of the webhook event that triggered the workflow. 40 | * githubActor: The name of the person or app that initiated the workflow. For example, octocat. 41 | * githubAction: Always set to true when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions. 42 | * githubApiUrl: The base URL for the REST API endpoint for your GitHub instance. For example, `https://api.github.com`. This is used to construct Artifact objects for each of the modified or added files when present. 43 | * modifiedFiles: A list of all the modified or added files in the commmit that triggered the workflow. For example, `["README.md", ".github/workflows/release.yaml"]`. If the `github_token` parameter is missing from the step config, or if the list of modified files is so large the SNS message body would exceed 256 KB, this value is set to an empty list instead. 44 | 45 | ### Additional Parameters 46 | 47 | To pass additional parameters to the pipeline execution context, include the `parameters` input. Each key/value pair will be passed to Spinnaker and can be used in pipeline steps. 48 | 49 | ```yaml 50 | steps: 51 | - name: Spinnaker 52 | uses: ExpediaGroup/spinnaker-pipeline-trigger@v1 53 | with: 54 | github_token: ${{ secrets.GITHUB_TOKEN }} 55 | topic_arn: ${{ secrets.SPINNAKER_TOPIC_ARN }} 56 | parameters: | 57 | parameter1: value1 58 | ``` 59 | 60 | Parameters are automatically added to `Parameters` of the pipeline. There is no need to define them separately. 61 | 62 | ![Spinnaker Parameter Config](docs/assets/custom-parameters.png) 63 | 64 | ### Message Attributes 65 | 66 | To trigger a particular pipeline in a Spinnaker project with multiple pipelines, include the `message_attributes` input. 67 | Then add the corresponding message attributes to the `Payload Constraints` of the pipeline you wish to trigger. 68 | 69 | ```yaml 70 | steps: 71 | - name: Spinnaker 72 | uses: ExpediaGroup/spinnaker-pipeline-trigger@v1 73 | with: 74 | github_token: ${{ secrets.GITHUB_TOKEN }} 75 | topic_arn: ${{ secrets.SPINNAKER_TOPIC_ARN }} 76 | parameters: | 77 | parameter1: value1 78 | message_attributes: awesome-attribute 79 | ``` 80 | 81 | ![Spinnaker Message Attributes](docs/assets/message-attributes.png) 82 | 83 | ## Requirements 84 | 85 | This action uses SNS to send the message to Spinnaker. Permissions and configuraiton are needed for the runner and Spinnaker. 86 | 87 | ### Runner 88 | 89 | The runner requires `sns:Publish` permissions. If using a public runner, something like [configure-aws-credentials](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) can be used. 90 | 91 | ### Spinnaker 92 | 93 | Follow Spinnaker's directions for [setting up a topic and queue](https://spinnaker.io/setup/triggers/amazon/) with the following modifications. 94 | 95 | * Do not set up the S3 notification 96 | * `messageFormat` should be `CUSTOM` 97 | * Include the template below with the `echo` portion of the config to receive GitHub file artifacts on the triggered pipelines. If you are running Echo in sharded mode, this config should be included in the scheduler instances. 98 | 99 | Sample message format based on the default parameters being sent: 100 | ```json 101 | [ 102 | {% for item in modifiedFiles %} 103 | { 104 | "customKind": false, 105 | "reference": "{{ githubApiUrl }}/repos/{{ repository }}/contents/{{ item }}", 106 | "metadata": {}, 107 | "name": "{{ item }}", 108 | "type": "github/file", 109 | "version": "{{ commit }}" 110 | }{% if not loop.last %},{% endif %} 111 | {% endfor %} 112 | ] 113 | ``` 114 | 115 | ## License 116 | 117 | The scripts and documentation in this project are released under the [Apache 2 License](https://github.com/ExpediaGroup/spinnaker-pipeline-trigger/blob/main/LICENSE). 118 | 119 | ## Contributions 120 | 121 | * Run `yarn all` locally before committing. 122 | * Coverage limits are set at 90%. 123 | * Follow semantic-release commit formatting. 124 | -------------------------------------------------------------------------------- /__tests__/main.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Expedia, Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | https://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | const githubContext = { 18 | repo: { 19 | owner: 'Org', 20 | repo: 'actions-test-trigger' 21 | }, 22 | sha: 'long-sha' 23 | } 24 | const mockedGetCommit = jest.fn() 25 | const mockOctokit = { 26 | rest: { 27 | repos: { 28 | getCommit: mockedGetCommit 29 | } 30 | } 31 | } 32 | 33 | import { SNSClient, PublishCommand } from '@aws-sdk/client-sns' 34 | import { run } from '../src/main' 35 | 36 | // Capture environment variables before running tests 37 | const cleanEnv = process.env 38 | jest.mock('@actions/github', () => { 39 | return { 40 | context: githubContext, 41 | getOctokit: () => mockOctokit 42 | } 43 | }) 44 | 45 | jest.mock('@aws-sdk/client-sns') 46 | const mockedSend = jest.fn().mockReturnValue({ MessageId: '1' }) 47 | 48 | describe('Publish', () => { 49 | beforeEach(() => { 50 | jest.resetModules() 51 | process.env = {} 52 | process.env.INPUT_TOPIC_ARN = 53 | 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 54 | process.env.GITHUB_REPOSITORY = 'Org/actions-test-trigger' 55 | process.env.GITHUB_SHA = 'long-sha' 56 | process.env.GITHUB_REF = 'main' 57 | process.env.GITHUB_API_URL = 'https://api.github.com' 58 | SNSClient.prototype.send = mockedSend 59 | }) 60 | 61 | test('Run with no options', async () => { 62 | // Arrange 63 | const region = 'us-west-2' 64 | 65 | const input = { 66 | Message: 67 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"main","githubEventName":"","githubActor":"","githubAction":"","parameters":{},"messageAttributes":"","modifiedFiles":[]}', 68 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 69 | } 70 | 71 | // Act 72 | await run() 73 | 74 | // Assert 75 | expect(SNSClient).toBeCalledWith({ region }) 76 | expect(PublishCommand).toBeCalledWith(input) 77 | expect(mockedSend).toBeCalledTimes(1) 78 | expect(mockedGetCommit).not.toHaveBeenCalled() 79 | }) 80 | 81 | test('No REF passed in', async () => { 82 | // Arrange 83 | const region = 'us-west-2' 84 | process.env.GITHUB_REF = '' 85 | 86 | const input = { 87 | Message: 88 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"","githubEventName":"","githubActor":"","githubAction":"","parameters":{},"messageAttributes":"","modifiedFiles":[]}', 89 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 90 | } 91 | 92 | // Act 93 | await run() 94 | 95 | // Assert 96 | expect(SNSClient).toBeCalledWith({ region }) 97 | expect(PublishCommand).toBeCalledWith(input) 98 | expect(mockedSend).toBeCalledTimes(1) 99 | expect(mockedGetCommit).not.toHaveBeenCalled() 100 | }) 101 | test('With Parameters and Message Attributes', async () => { 102 | // Arrange 103 | const region = 'us-west-2' 104 | process.env.INPUT_PARAMETERS = 'parameter1: value1\nparameter2: value2' 105 | process.env.INPUT_MESSAGE_ATTRIBUTES = 'my-attribute' 106 | 107 | const input = { 108 | Message: 109 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"main","githubEventName":"","githubActor":"","githubAction":"","parameters":{"parameter1":"value1","parameter2":"value2"},"messageAttributes":"my-attribute","modifiedFiles":[]}', 110 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 111 | } 112 | 113 | // Act 114 | await run() 115 | 116 | // Assert 117 | expect(SNSClient).toBeCalledWith({ region }) 118 | expect(PublishCommand).toBeCalledWith(input) 119 | expect(mockedSend).toBeCalledTimes(1) 120 | expect(mockedGetCommit).not.toHaveBeenCalled() 121 | }) 122 | 123 | describe('when github_token is present', () => { 124 | beforeEach(() => { 125 | process.env.INPUT_GITHUB_TOKEN = 'token' 126 | }) 127 | 128 | test('when commit response has no files it returns an empty list for modifiedFiles', async () => { 129 | // Arrange 130 | const region = 'us-west-2' 131 | 132 | const input = { 133 | Message: 134 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"main","githubEventName":"","githubActor":"","githubAction":"","parameters":{},"messageAttributes":"","modifiedFiles":[]}', 135 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 136 | } 137 | mockedGetCommit.mockResolvedValueOnce({ 138 | data: {} 139 | }) 140 | 141 | // Act 142 | await run() 143 | 144 | // Assert 145 | expect(SNSClient).toBeCalledWith({ region }) 146 | expect(PublishCommand).toBeCalledWith(input) 147 | expect(mockedSend).toBeCalledTimes(1) 148 | expect(mockedGetCommit).toBeCalledWith({ 149 | owner: 'Org', 150 | repo: 'actions-test-trigger', 151 | ref: 'long-sha' 152 | }) 153 | }) 154 | 155 | test('it returns a list of modified and added files', async () => { 156 | // Arrange 157 | const region = 'us-west-2' 158 | 159 | const input = { 160 | Message: 161 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"main","githubEventName":"","githubActor":"","githubAction":"","parameters":{},"messageAttributes":"","modifiedFiles":["file1","file2","file4"]}', 162 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 163 | } 164 | mockedGetCommit.mockResolvedValueOnce({ 165 | data: { 166 | files: [ 167 | { filename: 'file1', status: 'added' }, 168 | { filename: 'file2', status: 'modified' }, 169 | { filename: 'file3', status: 'removed' }, 170 | { filename: 'file4', status: 'added' } 171 | ] 172 | } 173 | }) 174 | 175 | // Act 176 | await run() 177 | 178 | // Assert 179 | expect(SNSClient).toBeCalledWith({ region }) 180 | expect(PublishCommand).toBeCalledWith(input) 181 | expect(mockedSend).toBeCalledTimes(1) 182 | expect(mockedGetCommit).toBeCalledWith({ 183 | owner: 'Org', 184 | repo: 'actions-test-trigger', 185 | ref: 'long-sha' 186 | }) 187 | }) 188 | 189 | test('when the message is too large it returns an empty list for modifiedFiles', async () => { 190 | // Arrange 191 | const region = 'us-west-2' 192 | 193 | const input = { 194 | Message: 195 | '{"repository":"Org/actions-test-trigger","commit":"long-sha","githubApiUrl":"https://api.github.com","ref":"main","githubEventName":"","githubActor":"","githubAction":"","parameters":{},"messageAttributes":"","modifiedFiles":[]}', 196 | TopicArn: 'arn:aws:sns:us-west-2:123456789123:spinnaker-github-actions' 197 | } 198 | mockedGetCommit.mockResolvedValueOnce({ 199 | data: { 200 | files: Array.from({ length: 500000 }, (_value, index) => { 201 | return { filename: `file${index}`, status: 'added' } 202 | }) 203 | } 204 | }) 205 | 206 | // Act 207 | await run() 208 | 209 | // Assert 210 | expect(SNSClient).toBeCalledWith({ region }) 211 | expect(PublishCommand).toBeCalledWith(input) 212 | expect(mockedSend).toBeCalledTimes(1) 213 | expect(mockedGetCommit).toBeCalledWith({ 214 | owner: 'Org', 215 | repo: 'actions-test-trigger', 216 | ref: 'long-sha' 217 | }) 218 | }) 219 | }) 220 | }) 221 | 222 | describe('fail', () => { 223 | beforeEach(() => { 224 | jest.resetModules() 225 | process.env = { ...cleanEnv } 226 | }) 227 | 228 | test('no ARN', async () => { 229 | // Arrange 230 | const mockedSend = jest.fn() 231 | 232 | // Act 233 | await run() 234 | 235 | // Assert 236 | expect(SNSClient).not.toBeCalled() 237 | expect(PublishCommand).not.toBeCalled() 238 | expect(mockedSend).not.toBeCalled() 239 | expect(mockedGetCommit).not.toHaveBeenCalled() 240 | }) 241 | }) 242 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------