Skip to content

Commit bfe991b

Browse files
authored
Add publishing gh actions, update existing actions (#131)
* Add publishing gh actions, update existing actions * Fix yaml typo * Add additional triggers for ci tests * Downgrade actions/setup node * Simplify getting npm package version in for release notes * adjust workflow push criteria
1 parent 9df41e3 commit bfe991b

File tree

6 files changed

+189
-6
lines changed

6 files changed

+189
-6
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### Summary
2+
3+
<!-- Summarize the change and indicate whether this will be a major/minor/patch change -->
4+
5+
### Checklist
6+
7+
- [ ] Added a changelog entry
8+
9+
### Authors
10+
11+
> List GitHub usernames for everyone who contributed to this pull request.
12+
13+
-
14+
15+
### Reviewers
16+
17+
@braintree/team-sdk-js

.github/workflows/ci-functional-tests.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: "Functional Tests"
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
workflow_dispatch:
8+
pull_request:
9+
branches:
10+
- '*'
411

512
jobs:
613
build:
@@ -10,9 +17,9 @@ jobs:
1017
steps:
1118
- uses: actions/checkout@v2
1219
- name: Use Node.js
13-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v2
1421
with:
15-
node-version: "18.x"
22+
node-version-file: .nvmrc
1623
- run: npm install
1724
- run: sudo apt-get install xvfb
1825
# there's a weird typescript incompatibility with jest types and mocha types

.github/workflows/ci-unit-tests.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: "Unit Tests"
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
workflow_dispatch:
8+
workflow_call:
9+
pull_request:
10+
branches:
11+
- '*'
412

513
jobs:
614
build:
@@ -10,9 +18,9 @@ jobs:
1018
steps:
1119
- uses: actions/checkout@v2
1220
- name: Use Node.js
13-
uses: actions/setup-node@v1
21+
uses: actions/setup-node@v4
1422
with:
15-
node-version: "18.x"
23+
node-version-file: .nvmrc
1624
- run: npm install
1725
- run: npm run lint
1826
- run: npm run test:unit

.github/workflows/publish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This workflow will run tests using node, bump the npm version, deploy to npm, and create a release with notes
2+
3+
name: Publish to npm
4+
run-name: Deploy ${{ github.repository }} to npmjs by @${{ github.actor }}
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version_type:
9+
description: "Version bump type (major, minor, patch)"
10+
required: true
11+
type: choice
12+
options:
13+
- major
14+
- minor
15+
- patch
16+
17+
env:
18+
NPM_REGISTRY: https://registry.npmjs.org/
19+
20+
concurrency: # prevent concurrent releases
21+
group: npm-publish
22+
cancel-in-progress: true
23+
24+
jobs:
25+
ci-unit-tests:
26+
uses: ./.github/workflows/ci-unit-tests.yml
27+
bump-version:
28+
needs: ci-unit-tests
29+
uses: ./.github/workflows/version-bump.yml
30+
with:
31+
version_type: ${{ inputs.version_type }}
32+
publish-npm:
33+
needs: bump-version
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version-file: .nvmrc
40+
registry-url: ${{ env.NPM_REGISTRY }}
41+
- run: npm ci
42+
- run: npm publish --provenance
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.BRAINTREE_NPM_ACCESS_TOKEN }}
45+
publish-release:
46+
needs: publish-npm
47+
uses: ./.github/workflows/release-notes.yml

.github/workflows/release-notes.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will create a release for the most recent deploy
2+
3+
name: Create release
4+
run-name: Running github release
5+
on:
6+
workflow_dispatch:
7+
workflow_call:
8+
9+
jobs:
10+
create_release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: .nvmrc
17+
18+
- name: Get version
19+
run: echo "latest_version=$(npm pkg get version --workspaces=false | tr -d \")" >> $GITHUB_ENV
20+
21+
- name: Get details
22+
run: |
23+
{
24+
echo 'release_details<<EOF'
25+
awk '/^## / { if (p) exit; p=1 } p' CHANGELOG.md | sed '1d'
26+
echo EOF
27+
} >> $GITHUB_ENV
28+
29+
- name: Create Release
30+
id: create_release
31+
uses: actions/create-release@v1
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
34+
with:
35+
tag_name: ${{ env.latest_version }}
36+
release_name: v${{ env.latest_version }}
37+
body: "${{ env.release_details }}"
38+
draft: false
39+
prerelease: false

.github/workflows/version-bump.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This workflow will bump the version
2+
3+
name: Bump version and update changelog
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
version_type:
9+
description: "Version bump type (major, minor, patch)"
10+
required: true
11+
type: string
12+
workflow_dispatch:
13+
inputs:
14+
version_type:
15+
description: "Version bump type (major, minor, patch)"
16+
required: true
17+
type: choice
18+
options:
19+
- major
20+
- minor
21+
- patch
22+
23+
jobs:
24+
version_bump:
25+
runs-on: ubuntu-latest
26+
27+
permissions:
28+
contents: write
29+
30+
steps:
31+
- name: Checkout Repo
32+
uses: actions/checkout@v4
33+
34+
- name: Configure Github Credentials
35+
run: |
36+
git config user.name 'github-actions[bot]'
37+
git config user.email 'github-actions[bot]@users.noreply.github.com'
38+
39+
- name: Check Changelog
40+
run: |
41+
if ! grep -i -q "## UNRELEASED" CHANGELOG.md; then
42+
echo "Error: 'UNRELEASED' not found in CHANGELOG.md. Please ensure the changelog is correctly formatted."
43+
exit 1
44+
fi
45+
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version-file: .nvmrc
49+
50+
- name: Bump npm version
51+
run: |
52+
new_version=$(npm version ${{ inputs.version_type }})
53+
echo "new_version=$(echo $new_version | sed 's/v//')" >> $GITHUB_ENV
54+
55+
- name: Update changelog
56+
run: |
57+
today=$(date +'%Y-%m-%d')
58+
sed -i "s/## unreleased/## ${{ env.new_version }} (${today})/i" CHANGELOG.md
59+
60+
- name: Commit and push changes
61+
run: |
62+
git tag -m ${{ env.new_version }} ${{ env.new_version }}
63+
git add --all
64+
git commit -m "v${{ env.new_version }}"
65+
git push

0 commit comments

Comments
 (0)