Skip to content

Commit

Permalink
Merge pull request #461 from OpenFn/autodeploy
Browse files Browse the repository at this point in the history
Auto-deploy releases on merge to main
  • Loading branch information
josephjclark authored Jan 13, 2024
2 parents 0d3a7f4 + 07c4669 commit d747030
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 9 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ name: CI

# Runs when a pull request is created or its head is updated
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
on:
pull_request:
push:
branches: [main]
on: pull_request

jobs:
build:
Expand All @@ -14,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [18]
node-version: [18.17.1]

steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: '18.17.1'
- uses: pnpm/action-setup@v2
with:
version: 8.6.8
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm test
- run: pnpm config set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run:
pnpm publish -r --report-summary --publish-branch main --access=public

- run: pnpm slack:notify
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@ dist
.fuse_*

.vscode/


/pnpm-publish-summary.json
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test:imports": "cd tools/import-tests && pnpm test",
"test": "pnpm lint && pnpm --filter \"./packages/**\" test && pnpm test:imports",
"lint": "pnpm --filter \"./packages/**\" lint",
"metadata": "pnpm -C tools/metadata cli"
"metadata": "pnpm -C tools/metadata cli",
"slack:notify": "cd tools/slack && pnpm notify"
},
"author": "Open Function Group",
"license": "ISC",
Expand Down
94 changes: 91 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tools/slack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@openfn/slack-notify",
"private": true,
"version": "1.0.0",
"description": "Util to notify npm publish changes to slack",
"main": "src/index.js",
"scripts": {
"notify": "node src/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@slack/web-api": "^6.8.1"
}
}
73 changes: 73 additions & 0 deletions tools/slack/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { readFileSync } = require('node:fs');
const { WebClient } = require('@slack/web-api');

const SLACK_DEV = 'C06DV9P91T6';
const DEVS = 'C05KZNPEJFN';
const IMPLEMENTATION = 'C017ELVRSM8';

const token = process.env.SLACK_TOKEN;
const slack = new WebClient(token);

const getMessage = changes => {
const blocks = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `🧩 *New adaptors releases* ✨`,
},
},
];

const versions = changes.publishedPackages.map(
pkg => `${pkg.version.padEnd(10)} ${pkg.name}`
);

const attachments = [
{
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `\`\`\`${versions.join('\n')}\`\`\``,
},
},
],
},
];

return {
blocks,
attachments,
};
};

const file = readFileSync('../../pnpm-publish-summary.json');
if (file) {
const json = JSON.parse(file);
if (json.publishedPackages.length) {
console.log('Generating slack post for all releases');
console.log();

const message = getMessage(json);
console.log(JSON.stringify(message));

slack.chat.postMessage({
...message,
channel: DEVS,
});
slack.chat.postMessage({
...message,
channel: IMPLEMENTATION,
});

console.log();
console.log('Done!');
} else {
console.log('No releases to report');
}
} else {
console.error('ERROR: no pnpm-publish-summary.json found');
process.exit(1);
}

0 comments on commit d747030

Please sign in to comment.