Skip to content

Commit

Permalink
Add publish with changeset in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
torifat committed Sep 9, 2019
1 parent 6611be8 commit 126ee2e
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with mono-repos or single package repos to help you verion and release 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/master/docs/common-questions.md)
83 changes: 83 additions & 0 deletions .changeset/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require('dotenv').config();
const { getInfo } = require('@changesets/get-github-info');

const changesetOptions = {
// If true, we will automatically commit the changeset when the command is run
commit: false,
};

// This function takes information about a changeset to generate an entry for it in your
// changelog. We provide the full changeset object as well as the version.
// It may be a good idea to replace the commit hash with a link to the commit.

/* the default shape is:
### Bump Type
- GIT_HASH: A summary message you wrote, indented?
*/

const getReleaseLine = async (changeset, type) => {
const [firstLine, ...futureLines] = changeset.summary
.split('\n')
.map(l => l.trimRight());
// getInfo exposes the GH username and PR number if you want them directly
// but it also exposes a set of links for the commit, PR and GH username
let { user, pull, links } = await getInfo({
repo: process.env.GITHUB_REPOSITORY,
commit: changeset.commit,
});
return `- ${links.commit}${links.pull === null ? '' : ` ${links.pull}`}${
links.user === null ? '' : ` Thanks ${links.user}!`
}: ${firstLine}\n${futureLines.map(l => ` ${l}`).join('\n')}`;
};

// This function takes information about what dependencies we are updating in the package.
// It provides an array of related changesets, as well as the dependencies updated.

/*
- Updated dependencies: [ABCDEFG]:
- Updated dependencies: [HIJKLMN]:
- [email protected]
- [email protected]
*/
const getDependencyReleaseLine = async (changesets, dependenciesUpdated) => {
if (dependenciesUpdated.length === 0) return '';

const changesetLinks = changesets.map(
changeset => `- Updated dependencies [${changeset.commit}]:`
);

const updatedDepenenciesList = dependenciesUpdated.map(
dependency => ` - ${dependency.name}@${dependency.version}`
);

return [...changesetLinks, ...updatedDepenenciesList].join('\n');
};

const versionOptions = {
// If true, we will automatically commit the version updating when the command is run
commit: false,
// Adds a skipCI flag to the commit - only valid if `commit` is also true.
skipCI: false,
// Do not modify the `changelog.md` files for packages that are updated
updateChangelog: true,
// A function that returns a string. It takes in options about a change. This allows you to customise your changelog entries
getReleaseLine,
// A function that returns a string. It takes in options about when a pacakge is updated because
getDependencyReleaseLine,
// An array of arrays that defines packages that are linked.
// Linked packages are packages that should be at the same version when they're released.
// If you've used Lerna to version packages before, this is very similar.
linked: [[]],
};

const publishOptions = {
// This sets whether unpublished packages are public by default. We err on the side of caution here.
public: true,
};

module.exports = {
versionOptions,
changesetOptions,
publishOptions,
};
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push]
on: push

jobs:
test:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
branches:
- master
paths:
- '.changeset/*/*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.x

- name: Install Yarn
run: curl -o- -L https://yarnpkg.com/install.sh | bash

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Publish to npm
uses: changesets/action@master
with:
# The --otp=1 is to get around a bug in changesets
# It will be fixed in Changesets 2
publish: yarn release --otp=1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/coverage/
*.log
.vscode
.env
package-lock.json
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "7.0.0",
"@changesets/cli": "^1.3.0",
"@changesets/get-github-info": "^0.1.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.9.0",
"babel-plugin-add-module-exports": "^1.0.0",
"dotenv": "^8.1.0",
"eslint": "^6.3.0",
"eslint-config-prettier": "^6.2.0",
"eslint-plugin-jest": "^22.17.0",
Expand Down
Loading

0 comments on commit 126ee2e

Please sign in to comment.