Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linter settings #224

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
branches:
- main

name: Update Mailgun

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
env:
working-directory: ./update
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.16.1'
cache: 'npm'

- name: Install dependencies
run: npm ci
working-directory: ${{ env.working-directory }}

- name: Linter
run: npm run lint
working-directory: ${{ env.working-directory }}

- name: Apply changes
run: node update.js iojs.org
working-directory: ${{ env.working-directory }}
env:
MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }}
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
pull_request:
branches:
- main

name: Source Code Health

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
env:
working-directory: ./update
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.16.1'
cache: 'npm'

- name: Install dependencies
run: npm ci
working-directory: ${{ env.working-directory }}

- name: Linter
run: npm run lint
working-directory: ${{ env.working-directory }}

- name: Check changes
run: node update.js iojs.org --dry-run
working-directory: ${{ env.working-directory }}
env:
MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
credentials.json
node_modules

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ The [iojs.org](./iojs.org) directory contains the [aliases.json](./iojs.org/alia

Since access to the Mailgun API key is required, only members of the @nodejs/build-infra team have the permission to push code to the `main` branch. That was done in order to minimize the possibility of mismatches between the information in this repo, and the actual email routes that are set up.

### Procedure
### Automatic Procedure

There are two GitHub Actions workflows that run automatically when targeting changes to the `main` branch:
- `ci.yml` this workflow runs the update in `dry-run` mode and reports the changes that would be made. It is triggered by any PR against the `main` branch.
- `cd.yml` this workflow runs the update and actually applies the changes. It is triggered by any push to the `main` branch.
### Manual Procedure

The [update](./update) directory contains a node program which will read the aliases mapping file, fetch the list of mail routes from Mailgun and update the routes to make sure they match the required state. The program is run by passing it a domain name as an argument (`update/update.js iojs.org`).

The Mailgun API key for the given domain is required. It can be found in the `admin_logins.md` file in the secrets repo (build/infra/), or directly via the Rackspace API. The key should be stored as a file named `iojs.org/credentials.json` in the form: `{ "api-key": "key-abc..." }` within a code tree.
The Mailgun API key for the given domain is required. It can be found in the `admin_logins.md` file in the secrets repo (build/infra/), or directly via the Rackspace API. The key should be used as environment variable `MAILGUN_API_KEY` when running the program.


Optionally, you can create a `.env` file in the `update` directory with the following content:

```
MAILGUN_API_KEY=your-api-key
```

The programs can be used with `--dry-run` to verify the current status and what will be changed by an update.

Expand Down
1 change: 1 addition & 0 deletions update/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.16.1
4 changes: 2 additions & 2 deletions update/add-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const qs = require('querystring')

const url = 'https://api.mailgun.net/v3/routes'

function addRoute (domain, creds, description, expression, actions, callback) {
function addRoute (domain, description, expression, actions, callback) {
const params = {
description,
expression,
action: actions
}
const data = qs.stringify(params)
const options = {
auth: `api:${creds['api-key']}`,
auth: `api:${process.env.MAILGUN_API_KEY}`,
headers: {
'content-type': 'application/x-www-form-urlencoded',
'content-length': Buffer.byteLength(data)
Expand Down
4 changes: 2 additions & 2 deletions update/delete-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const jsonist = require('jsonist')

const url = 'https://api.mailgun.net/v3/routes'

function deleteRoute (domain, creds, id, callback) {
const options = { auth: `api:${creds['api-key']}` }
function deleteRoute (domain, id, callback) {
const options = { auth: `api:${process.env.MAILGUN_API_KEY}` }
jsonist.delete(`${url}/${id}`, options, callback)
}

Expand Down
4 changes: 2 additions & 2 deletions update/list-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const jsonist = require('jsonist')

const url = 'https://api.mailgun.net/v3/routes'

function listRoutes (domain, creds, callback) {
const options = { auth: `api:${creds['api-key']}` }
function listRoutes (domain, callback) {
const options = { auth: `api:${process.env.MAILGUN_API_KEY}` }
jsonist.get(url, options, callback)
}

Expand Down
Loading