Skip to content

Commit d6f6dda

Browse files
committed
Merge branch 'master' into feature/insert (documentcloud#199)
2 parents ac922d1 + b83d9d0 commit d6f6dda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3511
-19232
lines changed

.github/workflows/cd.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This workflow is like CI, but also builds the documentation and deploys to NPM
2+
# and gh-pages.
3+
4+
name: Continuous Deployment
5+
6+
on:
7+
push:
8+
branches: [prepublish]
9+
workflow_run:
10+
workflows: [Prepublication staging]
11+
types: [completed]
12+
13+
jobs:
14+
deploy:
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
with:
21+
ref: prepublish
22+
- name: Use Node.js 14.x
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: 14.x
26+
- name: Configure yarn cache path
27+
run: yarn config set cache-folder ~/.yarn-cache
28+
- name: Restore yarn cache
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/.yarn-cache
32+
key: yarn-cache-14.x
33+
restore-keys: |
34+
yarn-cache-
35+
- name: Restore node_modules
36+
uses: actions/cache@v2
37+
with:
38+
path: node_modules
39+
key: node-modules-14.x-${{ hashFiles('yarn.lock') }}
40+
restore-keys: |
41+
node-modules-14.x-
42+
node-modules-
43+
- name: Install dependencies
44+
run: yarn
45+
- name: Build dist files and docs and run the tests
46+
run: yarn grunt dist docco tocdoc
47+
- name: Commit the build output
48+
uses: EndBug/add-and-commit@v5
49+
with:
50+
add: dist/ index.html
51+
message: Autocommit build output (continuous deployment)
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
- name: Publish to NPM
55+
run: yarn publish
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
- name: Merge into gh-pages
59+
uses: devmasx/[email protected]
60+
with:
61+
type: now
62+
target_branch: gh-pages
63+
github_token: ${{ secrets.GITHUB_TOKEN }}
64+
- uses: actions/checkout@v2
65+
with:
66+
ref: gh-pages
67+
- name: Tag the release
68+
uses: Klemensas/action-autotag@stable
69+
with:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
tag_prefix: v

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This workflow will install the node_modules, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Continuous Integration
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [10.x, 14.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- name: Configure yarn cache path
27+
run: yarn config set cache-folder ~/.yarn-cache
28+
- name: Restore yarn cache
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/.yarn-cache
32+
key: yarn-cache-${{ matrix.node-version }}
33+
restore-keys: |
34+
yarn-cache-
35+
- name: Restore node_modules
36+
uses: actions/cache@v2
37+
with:
38+
path: node_modules
39+
key: node-modules-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}
40+
restore-keys: |
41+
node-modules-${{ matrix.node-version }}-
42+
node-modules-
43+
- name: Install dependencies
44+
run: yarn
45+
- name: Run linter, concat, minifier and tests
46+
run: yarn dist

.github/workflows/prepublish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# As an alternative to a manual push to the prepublish branch, this workflow can
2+
# be triggered on a release branch by assigning a special label to its pull
3+
# request in order to set the CD circus in motion.
4+
5+
name: Prepublication staging
6+
7+
on:
8+
pull_request:
9+
types: [labeled]
10+
# Would filter by branch here, but GH Actions wrongly decides not to
11+
# trigger the workflow if we do this.
12+
13+
jobs:
14+
stage:
15+
runs-on: ubuntu-latest
16+
# Filtering by branch here instead. Credit due to @MiguelSavignano.
17+
# https://github.com/devmasx/merge-branch/issues/11
18+
if: contains(github.event.pull_request.head.ref, 'release/') || contains(github.event.pull_request.head.ref, 'hotfix/')
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Merge into prepublish
22+
uses: devmasx/[email protected]
23+
with:
24+
label_name: ready to launch
25+
target_branch: prepublish
26+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ examples/*.css
88
examples/*.html
99
examples/public
1010
bower_components/*
11+
dist/
12+
/index.html

.travis.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@ Create your own fork of contrib where you can make your changes.
1010

1111
## 3. Install development dependencies
1212

13-
Make sure you have [Node.js][node] and the [grunt cli][cli] installed. Then install contrib's development dependencies with `npm install`.
13+
Make sure you have [Node.js][node] and [Yarn][yarn] installed. Then install contrib's development dependencies with `yarn`. Note that these dependencies include the [Grunt CLI][cli] which we use for task automation.
1414

1515
## 4. Change the code
1616

1717
Make your code changes, ensuring they adhere to the same [coding style as Underscore][style]. Do **not** edit the files in `dist/`.
1818

19-
Make any necessary updates to the qUnit tests found in `test/`. Run `grunt test` to catch any test failures or lint issues. You can also use `grunt watch:test` to get instant feedback each time you save a file.
19+
Make any necessary updates to the qUnit tests found in `test/`. Run `yarn test` to catch any test failures or lint issues. You can also use `yarn grunt watch:test` to get instant feedback each time you save a file.
2020

2121
## 5. Update the docs
2222

2323
Make any necessary documentation updates in `docs/`. Do **not** edit `index.html` directly.
2424

25-
After updating the docs, run `grunt tocdoc` to rebuild the `index.html` file. Visually inspect `index.html` in your browser to ensure the generated docs look nice.
25+
After updating the docs, run `yarn tocdoc` to rebuild the `index.html` file. Visually inspect `index.html` in your browser to ensure the generated docs look nice.
2626

2727
## 6. Send a pull request
2828

2929
Send a pull request to `documentcloud/underscore-contrib` for feedback.
3030

31-
If modifications are necessary, make the changes and rerun `grunt test` or `grunt tocdoc` as needed.
31+
If modifications are necessary, make the changes and rerun `yarn test` or `yarn tocdoc` as needed.
3232

3333
And hopefully your pull request will be merged by the core team! :-)
3434

3535
[style]:https://github.com/documentcloud/underscore/blob/master/underscore.js
3636
[node]:http://nodejs.org/
37-
[cli]:http://gruntjs.com/getting-started#installing-the-cli
37+
[yarn]:https://classic.yarnpkg.com/
38+
[cli]:http://gruntjs.com/getting-started#installing-the-cli

DEPLOYING.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# How to cut a new release for Underscore-contrib
2+
3+
This is a checklist for repository maintainers. It covers all the steps involved in releasing a new version, including publishing to NPM and updating the `gh-pages` branch. We have tried to automate as many of these steps as possible using GitHub Actions. The workflows involved are in the (hidden) `.github` directory.
4+
5+
A "regular" release includes new changes that were introduced to the `master` branch since the previous release. A *hotfix* release instead skips any such changes and only addresses urgent problems with the previous release.
6+
7+
8+
## Steps
9+
10+
1. Ensure your local `master` branch descends from the previous release branch and that it is in a state that you want to release. **Exception:** for hotfixes, ensure you have an up-to-date local copy of the previous release branch instead.
11+
2. Decide on the next version number, respecting [semver][semver]. For the sake of example we'll use `1.2.3` as a placeholder version throughout this checklist.
12+
3. Create a `release/1.2.3` branch based on `master`. **Exception:** if this is a hotfix, start from the previous release branch instead and call it `hotfix/1.2.3`.
13+
4. Bump the version number in the `package.json` and the `yarn.lock` by running the command `yarn version --no-git-tag-version`, with the extra flag `--major`, `--minor` or `--patch` depending on which part of the version number you're incrementing (e.g., `--patch` if you're bumping from 1.2.2 to 1.2.3). Note that you can configure `yarn` to always include the `--no-git-tag-version` flag so you don't have to type it every time.
14+
5. Bump the version number in the source code and in `docs/index.md` accordingly.
15+
6. Commit the changes from steps 4 and 5 with a commit message of the format `Bump the version to 1.2.3`.
16+
7. Add more commits to extend the change log and to update any other documentation that might require it. Ensure that all documentation looks good.
17+
8. Push the release branch and create a pull request against `master` (also if it is a hotfix).
18+
9. At your option, have the release branch reviewed and add more commits to satisfy any change requests.
19+
10. The "Continuous Integration" workflow will trigger automatically on the pull request. This runs the test suite against multiple environments. Wait for all checks to complete.
20+
11. If any checks fail, add more commits to fix and repeat from step 10.
21+
12. When all reviewers are satisfied and all checks pass, apply the "ready to launch" label to the pull request. This will trigger the "Prepublication staging" workflow, which will merge the release branch into the `prepublish` branch. Merge manually if the workflow fails for whatever reason. **Note:** do *not* merge into `master` yet.
22+
13. The merging of new changes into `prepublish` will trigger the "Continuous Deployment" workflow, which is documented below. **Pay attention as the deployment workflow progresses.**
23+
14. If the deployment workflow fails, identify the failing step and address as quickly as possible. Possible solution steps include:
24+
- Adding new commits to the release branch and repeating from step 12 (most likely if the docs fail to build for some reason).
25+
- Manually pushing new commits to the `prepublish` branch and repeating from step 13 (this might be needed in case of merge conflicts, although this is highly unlikely).
26+
- Manually running `yarn publish` (if something is wrong with the NPM registry or the authentication credentials).
27+
- Manually merging `prepublish` into `gh-pages` (in unlikely case of merge conflicts).
28+
- Manually tagging the release on `gh-pages`.
29+
15. When the deployment workflow has completed, double-check that the new version was published to NPM, that the website was updated and that the repository contains a tag for the new release.
30+
16. Finally merge the release branch into `master`, but keep the branch around for a few days in case you need to do a hotfix.
31+
17. Delete the release branch. You can still restore it if necessary, by tracing the history graph two commits back from the release tag.
32+
33+
34+
## Automated continuous deployment workflow
35+
36+
This workflow is defined in `.github/workflows/cd.yml`. Note that roughly the first half of the steps in that file consists of basic boilerplate to check out the source and install dependencies.
37+
38+
The publishing to NPM depends on a [secret][secrets] named `NPM_TOKEN`, representing the API token of the NPM account that owns the `underscore-contrib` package. Only admins of the documentcloud organization can access this setting.
39+
40+
1. Checkout the source, restore caches and install the dependencies.
41+
2. Run `yarn grunt dist docco tocdoc`.
42+
3. Commit the output of the previous step to the `prepublish` branch.
43+
4. Publish to NPM.
44+
5. Merge the `prepublish` branch into `gh-pages`.
45+
6. Tag the tip of `gh-pages` with the version number in the `package.json`.
46+
47+
48+
[semver]: https://semver.org
49+
[secrets]: https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ module.exports = function(grunt) {
8888
}
8989
});
9090

91-
grunt.registerTask("test", ["jshint", "qunit:main"]);
92-
grunt.registerTask("dist", ["concat", "uglify"]);
91+
grunt.registerTask('test', ['jshint', 'qunit:main']);
9392
grunt.registerTask('default', ['test']);
9493
grunt.registerTask('dist', ['test', 'concat', 'qunit:concat', 'uglify', 'qunit:min']);
94+
grunt.registerTask('doc', ['test', 'tocdoc']);
9595
};

0 commit comments

Comments
 (0)