Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
david-espi-hernandez committed Jun 7, 2023
1 parent 1357d99 commit bd32cf3
Show file tree
Hide file tree
Showing 34 changed files with 15,128 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
5 changes: 5 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: "javascript-action CodeQL config"

paths-ignore:
- node_modules
- dist
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily

- package-ecosystem: npm
directory: /
schedule:
interval: daily
51 changes: 51 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/

on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:

jobs:
check-dist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/[email protected]
with:
node-version: 16.x

- name: Install dependencies
run: npm ci

- name: Rebuild the dist/ directory
run: npm run prepare

- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '24 5 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "units-test"
on:
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
# unit tests
units:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm test
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
node_modules/

# Editors
.vscode/
.idea/
*.iml

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Other Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @davidespihernandez
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Postman Inc.
Copyright (c) 2019 GitHub Actions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# push-openapi-to-postman
Github action that pushes an OpenAPI in the repository to a specific API in a Postman workspace, creating a new version.

Pushes an OpenAPI definition in your repository to Postman, creating a new version on an existing API.


## Usage
Example of manual trigger, asking for the required inputs.

```yaml
name: Sync OpenAPI with Postman
on:
workflow_dispatch:
inputs:
versionName:
description: 'The new version name'
required: true
default: '1.0.0'
releaseNotes:
description: 'The new version release notes'
required: false
default: ''
jobs:
sync-with-postman-api:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Push OpenAPI to Postman
id: pushApi
uses: davidespihernandez/push-openapi-to-postman@v1
with:
path-to-definition: ./api_definition.json
postman-api-key: ${{ secrets.POSTMAN_API_KEY }}
api-id: ${{ vars.API_ID }}
api-path-to-file-name: index.json
version-name: ${{ github.event.inputs.versionName }}
release-notes: ${{ github.event.inputs.releaseNotes }}
```
For the previous example to work you need to define:
- An environment variable `API_ID` containing the API id that is going to be updated
- A secret called `POSTMAN_API_KEY` containing the Postman API key with admin permission on the API that is going to be modified.

Other things to take into account:

* Make sure the `path-to-definition` points to the file in your repo that contains your OpenAPI definition.
* The OpenAPI definition must be in JSON format.
* Make sure the file name to update in your API schema matches the value on the `api-path-to-file-name` input.


## License

MIT

41 changes: 41 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: push-openapi-to-postman
description: 'Reads a JSON OpenAPI definition from your repo and pushes it to an existing Postman API, creating a new version on it'
author: David Espí Hernández <[email protected]>
branding:
icon: arrow-up-circle
color: blue
inputs:
postman-api-key:
description: 'Postman API Key'
required: true
default: ''
path-to-definition:
description: 'Path to the OpenAPI definition file in the repository'
required: true
default: './openAPI.json'
api-id:
description: 'Postman API ID'
required: true
default: 'String'
schema-id:
description: 'Postman schema id on the previous API'
required: true
default: 'String'
api-path-to-file-name:
description: 'The path and file name on the API where the definition should be updated'
required: true
default: 'index.json'
version-name:
description: 'The new version name'
required: true
default: '1.0.0'
release-notes:
description: 'The new version release notes'
required: false
default: ''
outputs:
createdVersionId:
description: 'The newly created version ID'
runs:
using: 'node16'
main: 'dist/index.js'
11 changes: 11 additions & 0 deletions axiosUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const getAxiosConfig = (postmanApiKey) => {
return {
headers: {
'x-api-key': postmanApiKey,
Accept: 'application/vnd.api.v10+json',
'Content-Type': 'application/json',
}
}
}

module.exports = {getAxiosConfig};
16 changes: 16 additions & 0 deletions axiosUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const {getAxiosConfig} = require("./axiosUtils");


describe('test axiosUtils', () => {
test('getAxiosConfig returns expected config with headers', () => {
const API_KEY = 'POSTMAN_API_KEY'
const config = getAxiosConfig(API_KEY);
expect(config).toEqual({
headers: {
'x-api-key': API_KEY,
Accept: 'application/vnd.api.v10+json',
'Content-Type': 'application/json',
}
});
});
});
3 changes: 3 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const POSTMAN_API_BASE_URL = 'https://api.getpostman.com';

module.exports = {POSTMAN_API_BASE_URL};
Loading

0 comments on commit bd32cf3

Please sign in to comment.