Skip to content

Add publishing gh actions, update existing action #37

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 0 additions & 8 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

45 changes: 45 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report_form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Bug Report
description: File a bug report.
title: "[Bug]: "
labels: ["bug", "triage"]
projects: []
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Detail the bad behavior and the steps required to duplicate it
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: textarea
id: expected-behavior
attributes:
label: What did you expect to happen?
description: What did you expect to happen when performing the action?
placeholder: Expected behavior
value: "Expected behavior"
validations:
required: true
- type: input
id: version
attributes:
label: Version
description: What version of this library are you running?
placeholder: "v0.0.0"
value:
validations:
required: true
- type: textarea
id: browsers
attributes:
label: What browsers are you seeing the problem on?
description: List browsers where you see the problem reported.
placeholder: 'For each browser specify 1) operating system and version 2) browser name and version'
value: 'OS browser version'

1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request_form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Feature Request
description: Request a new feature.
title: "[FR]: "
labels: ["feature", "request", "enhancement", "triage"]
projects: []
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this feature request!
- type: textarea
id: feat-summary
attributes:
label: Feature Summary
description: In a few sentences or less, provide a concise description of the feature being requested.
placeholder: 'New feature that does ___; it can be used when ...'
validations:
required: true
- type: textarea
id: detailed-description
attributes:
label: Detailed description of new feature.
description: |
Please provide a detailed description of proposed feature.
- What problem would this new feature solve?
- How will this change affect users?
- Is it a modification to existing functionality? Are you requesting a new/modified function input or output? Please provide an example of what the change might look like?
placeholder: 'New feature details.'
validations:
required: true
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Summary

<!-- Summarize the change and indicate whether this will be a major/minor/patch change -->

### Checklist

- [ ] Added a changelog entry

### Authors

> List GitHub usernames for everyone who contributed to this pull request.

-

### Reviewers

@braintree/team-sdk-js
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: "Unit Tests"
name: "CI"

on: [push]
on:
push:
branches:
- 'main'
workflow_dispatch:
workflow_call:
pull_request:
branches:
- '*'

jobs:
build:
Expand All @@ -10,8 +18,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "18.x"
node-version-file: '.nvmrc'
- run: npm install
- run: npm test
50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow will run tests using node, bump the npm version, deploy to npm, and create a release with notes

name: Publish to npm
run-name: Deploy ${{ github.repository }} to npmjs by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
version_type:
description: "Version bump type (major, minor, patch)"
required: true
type: choice
options:
- patch
- minor
- major

env:
NPM_REGISTRY: https://registry.npmjs.org/

concurrency: # prevent concurrent releases
group: npm-publish
cancel-in-progress: true

jobs:
ci:
uses: ./.github/workflows/ci.yml
bump-version:
needs: ci
uses: ./.github/workflows/version-bump.yml
with:
version_type: ${{ inputs.version_type }}
publish-npm:
needs: bump-version
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: ${{ env.NPM_REGISTRY }}
- run: git pull # Pull down changes from previous step
- run: npm ci
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.BRAINTREE_NPM_ACCESS_TOKEN }}
publish-release:
needs: publish-npm
uses: ./.github/workflows/release-notes.yml
43 changes: 43 additions & 0 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will create a release for the most recent deploy

name: Create release
run-name: Running github release
on:
workflow_dispatch:
workflow_call:

jobs:
create_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- run: |
git checkout main
git pull

- name: Get version
run: echo "latest_version=$(npm pkg get version --workspaces=false | tr -d \")" >> $GITHUB_ENV

- name: Get details
run: |
{
echo 'release_details<<EOF'
awk '/^## / { if (p) exit; p=1 } p' CHANGELOG.md | sed '1d'
echo EOF
} >> $GITHUB_ENV

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ env.latest_version }}
release_name: v${{ env.latest_version }}
body: "${{ env.release_details }}"
draft: false
prerelease: false
65 changes: 65 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow will bump the version

name: Bump version and update changelog

on:
workflow_call:
inputs:
version_type:
description: "Version bump type (major, minor, patch)"
required: true
type: string
workflow_dispatch:
inputs:
version_type:
description: "Version bump type (major, minor, patch)"
required: true
type: choice
options:
- patch
- minor
- major

jobs:
version_bump:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Configure Github Credentials
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'

- name: Check Changelog
run: |
if ! grep -i -q "## UNRELEASED" CHANGELOG.md; then
echo "Error: 'UNRELEASED' not found in CHANGELOG.md. Please ensure the changelog is correctly formatted."
exit 1
fi

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

- name: Bump npm version
run: |
new_version=$(npm version ${{ inputs.version_type }})
echo "new_version=$(echo $new_version | sed 's/v//')" >> $GITHUB_ENV

- name: Update changelog
run: |
today=$(date +'%Y-%m-%d')
sed -i "s/## unreleased/## ${{ env.new_version }} (${today})/i" CHANGELOG.md

- name: Commit and push changes
run: |
git tag -m ${{ env.new_version }} ${{ env.new_version }}
git add --all
git commit -m "v${{ env.new_version }}"
git push