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

Create changesets workflow #145

Merged
merged 5 commits into from
Dec 4, 2023
Merged
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
46 changes: 46 additions & 0 deletions .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Changesets

on:
push:
branches:
- main
paths:
- "anghammarad-client-node/**"

permissions:
id-token: write
contents: write
pull-requests: write

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can
# generate changelogs with the correct commits
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install dependencies
run: cd anghammarad-client-node && yarn install --frozen-lockfile

- name: Run build script
run: cd anghammarad-client-node && yarn build

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: yarn changeset publish
title: "🦋 Release package updates"
commit: "Bump package version"
cwd: "./anghammarad-client-node"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 8 additions & 0 deletions anghammarad-client-node/.changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions anghammarad-client-node/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions anghammarad-client-node/.changeset/eighty-pants-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/anghammarad": patch
---

Test noop
1 change: 1 addition & 0 deletions anghammarad-client-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"aws-sdk": "^2.769.0"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@types/jest": "^26.0.14",
"jest": "^26.5.2",
"ts-jest": "^26.4.1",
Expand Down
126 changes: 97 additions & 29 deletions anghammarad-client-node/test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Anghammarad} from "../src/main";
import {NotifyParams, RequestedChannel} from "../src/interfaces";
import { Anghammarad } from "../src/main";
import { NotifyParams, RequestedChannel } from "../src/interfaces";

describe("The messageJson function", () => {
// Pass something in here so that we don't bother instantiating a client
// each time we run the tests
// each time we run tests
const client = new Anghammarad({} as any);

const defaultParams: NotifyParams = {
Expand All @@ -17,50 +17,118 @@ describe("The messageJson function", () => {
};

it("sets message as provided", () => {
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({message: "message"});
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({
message: "message",
});
});

it("sets sender as provided", () =>{
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({sender: "source"})
})
it("sets sender as provided", () => {
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({
sender: "source",
});
});

describe("represents channel correctly", () => {
it("for 'All'", () => {
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({channel: "all"})
})
expect(JSON.parse(client.messageJson(defaultParams))).toMatchObject({
channel: "all",
});
});

it("for 'Email'", () => {
expect(JSON.parse(client.messageJson({...defaultParams, channel: RequestedChannel.Email}))).toMatchObject({channel: "email"})
})
expect(
JSON.parse(
client.messageJson({
...defaultParams,
channel: RequestedChannel.Email,
})
)
).toMatchObject({ channel: "email" });
});

it("for 'Hangouts'", () => {
expect(JSON.parse(client.messageJson({...defaultParams, channel: RequestedChannel.HangoutsChat}))).toMatchObject({channel:"hangouts"})
})
expect(
JSON.parse(
client.messageJson({
...defaultParams,
channel: RequestedChannel.HangoutsChat,
})
)
).toMatchObject({ channel: "hangouts" });
});

it("for 'Prefer Email'", () => {
expect(JSON.parse(client.messageJson({...defaultParams, channel: RequestedChannel.PreferEmail}))).toMatchObject({channel:"prefer email"})
})
expect(
JSON.parse(
client.messageJson({
...defaultParams,
channel: RequestedChannel.PreferEmail,
})
)
).toMatchObject({ channel: "prefer email" });
});

it("for 'Prefer Hangouts'", () => {
expect(JSON.parse(client.messageJson({...defaultParams, channel: RequestedChannel.PreferHangouts}))).toMatchObject({channel:"prefer hangouts"})
})
})
expect(
JSON.parse(
client.messageJson({
...defaultParams,
channel: RequestedChannel.PreferHangouts,
})
)
).toMatchObject({ channel: "prefer hangouts" });
});
});

it("includes target", () => {
const result = JSON.parse(client.messageJson({...defaultParams, target: {Stack: "stack-name", App: "app-name"}}))
expect(result).toMatchObject({target:{Stack:"stack-name", App: "app-name"}})
})
const result = JSON.parse(
client.messageJson({
...defaultParams,
target: { Stack: "stack-name", App: "app-name" },
})
);
expect(result).toMatchObject({
target: { Stack: "stack-name", App: "app-name" },
});
});

it("includes actions", () => {
const result = JSON.parse(client.messageJson({...defaultParams, actions: [{cta: "cta1", url: "url1"}, {cta: "cta2", url: "url2"}]}))
expect(result).toMatchObject({actions: [{cta: "cta1", url: "url1"}, {cta: "cta2", url: "url2"}]})
})
const result = JSON.parse(
client.messageJson({
...defaultParams,
actions: [
{ cta: "cta1", url: "url1" },
{ cta: "cta2", url: "url2" },
],
})
);
expect(result).toMatchObject({
actions: [
{ cta: "cta1", url: "url1" },
{ cta: "cta2", url: "url2" },
],
});
});

it("produces valid JSON when quotes are contained in the data", () => {
expect(() => JSON.parse(client.messageJson({...defaultParams, message: `Message with "quotes"`}))).not.toThrow()
})
expect(() =>
JSON.parse(
client.messageJson({
...defaultParams,
message: `Message with "quotes"`,
})
)
).not.toThrow();
});

it("properly escapes input", () => {
expect(JSON.parse(client.messageJson({...defaultParams, message: `Message with "quotes"`}))).toMatchObject({message: `Message with "quotes"`})
})
})
expect(
JSON.parse(
client.messageJson({
...defaultParams,
message: `Message with "quotes"`,
})
)
).toMatchObject({ message: `Message with "quotes"` });
});
});
Loading