Skip to content

Commit

Permalink
Beta version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnlindsay committed Dec 13, 2023
1 parent 35562dd commit a7876e9
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 39 deletions.
24 changes: 12 additions & 12 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ Welcome! HelloSign Embedded is an open source project which allows HelloSign API
## Pull Requests

1. Fork the HelloSign Embedded repository.
2. Create a new branch for your changes ~each feature, fix or improvement.~
* Unless we introduce a release branch concept, this won't work well
3. Increment the version number in packages.json
2. Create a new branch for your changes of the latest `master` branch
3. Increment the version number in [packages.json](package.json)
4. Make your changes
5. Open a pull request, triggering a github action that does the following:
5. Add description of changes (matching format) to [CHANGELOG.md](/CHANGELOG.md)
6. Open a pull request, triggering a github action that does the following:
1. verify the version
2. build beta package
3. test beta package
4. generate a github tagged draft release
5. publish beta package to npm & our s3 staging CDN
6. Once the pull request is merged to master, github actions:
4. generate a github tag for beta release
5. publish beta package to npm
6. publish to our s3 staging CDN
7. Once the pull request is merged to master, github actions:
1. verifies the live version
2. build package
3. test package
4. generate release with release notes
5. generate github release tag
6. publish to npm
7. publish to our S3 CDN
3. test package
4. generate github release tag
5. publish to npm
6. publish to our S3 CDN

## License

Expand Down
63 changes: 50 additions & 13 deletions .github/actions-scripts/validate-release-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,77 @@ const { context, getOctokit } = require('@actions/github');
const { setOutput } = require('@actions/core');

const semver = require('semver');
const process = require('process');

console.assert(process.env.GITHUB_TOKEN, "GITHUB_TOKEN not present");

const octokit = getOctokit(process.env.GITHUB_TOKEN);
const workspace = process.env.GITHUB_WORKSPACE;

const beta_version_limit = 10;

const {
repo: { owner, repo },
payload: { number },
} = context;
console.assert(number, "number not present");

const gh_api_header = { headers: { 'X-GitHub-Api-Version': '2022-11-28' } }

main();

async function validateReleaseVersion() {
const {
repo: { owner, repo },
payload: { number },
} = context;
console.assert(number, "number not present");

const { version } = require(`${workspace}/package.json`);
console.log("Submitted Version: ", version)

const { data: latest } = await octokit.request(`GET /repos/${owner}/${repo}/releases/latest`, {
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
console.log("Latest Version: ", latest.name)
const { data: latest } = await octokit.request(`GET /repos/${owner}/${repo}/releases/latest`, gh_api_header)

// Version set in package.json must be greater than latest
console.log("Package Version: ", version, "Latest Version: ", latest.name)
if (! semver.gt(version, latest.name)) {
console.log("version property in package.json must be greater than: ", latest.name)
process.exit(1);
}
return version;
}


async function validateBetaVersion( version, beta_inc = 0 ) {

let beta_version = `${version}-beta.${beta_inc}`
console.log("Beta Version: ", beta_version)

if (beta_inc > beta_version_limit) {
console.log("Too many beta versions! (arbitrary limitation) ", beta_inc)
process.exit(1);
}

try {
const { data: beta_tag } = await octokit.request(
`GET /repos/${owner}/${repo}/git/refs/tags/${beta_version}`,
gh_api_header
)
console.log(`Tag exists (${beta_tag.ref}) bumping beta version and retrying`)
return validateBetaVersion( version, ++beta_inc );
} catch (error) {
if (error.status === 404) {
console.log(`OK to publish, no tag @ 'git/refs/tags/${beta_version}'`)
return beta_version;
} else {
console.log("Unknown oktokit error ", error.message)
process.exit(1);
}
}

return beta_version;
}

async function main() {
const version = await validateReleaseVersion();
setOutput("version", version);
if (process.argv[2] === '--beta') {
const beta_version = await validateBetaVersion(version);
setOutput("version", beta_version);
} else {
setOutput("version", version);
}
}
37 changes: 29 additions & 8 deletions .github/workflows/publish-beta-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
NPM_REGISTRY_URL: "https://registry.npmjs.com"
BETA_SUFFIX: 'testbeta'
BETA_SUFFIX: 'beta.0'
CDN_AWS_PUBLISH_ROLE: arn:aws:iam::654344198836:role/github-actions-oidc-role-nonprod-sign-embedded
CDN_BUCKET: cdn.staging-hellosign.com
CDN_PATH: public/js/embedded
Expand Down Expand Up @@ -43,19 +43,40 @@ jobs:
id: version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: .github/actions-scripts/validate-release-version.js
run: .github/actions-scripts/validate-release-version.js --beta

- name: Announce version
- name: Set Beta Version
env:
PACKAGE_VERSION: ${{ steps.version.outputs.version }}
run: |
echo "v${{ steps.version.outputs.version }} is the proposed new version."
echo "Setting beta version ${PACKAGE_VERSION}"
npm version ${PACKAGE_VERSION} --no-git-tag-version
- name: Pack
run: |
npm pack --pack-destination="./umd"
- name: Publish (dry-run)
- name: Create tag
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.version.outputs.version }}',
tag_name: 'v${{ steps.version.outputs.version }}',
name: 'v${{ steps.version.outputs.version }}',
draft: true,
prerelease: true,
sha: context.sha
})
- name: Publish Beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
npm publish --dry-run --access=public
npm publish --tag beta --provenance --access=public
- name: Configure AWS credentials for Non-Prod
id: awskeys
Expand All @@ -65,8 +86,8 @@ jobs:
aws-region: ${{ env.AWS_REGION }}

- name: Copy dev build to nonprod cdn
run: aws s3 cp umd/embedded.development.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}-${{ env.BETA_SUFFIX }}/
run: aws s3 cp umd/embedded.development.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}/

- name: Copy minified build to nonprod cdn
run: aws s3 cp umd/embedded.production.min.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}-${{ env.BETA_SUFFIX }}/
run: aws s3 cp umd/embedded.production.min.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}/

84 changes: 84 additions & 0 deletions .github/workflows/publish-prod-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Changes approved; deploy to prod

on:
push:
branches: [ "master" ]

env:
NPM_REGISTRY_URL: "https://registry.npmjs.com"
CDN_AWS_PUBLISH_ROLE: TBD
CDN_BUCKET: cdn.hellosign.com
CDN_PATH: public/js/embedded
AWS_REGION: us-east-1
jobs:
build:
permissions:
id-token: write # This is required for requesting the JWT
contents: write # This is required for publishing releases
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x] # we should pull this from a common place

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: ${{ env.NPM_REGISTRY_URL }}

- name: Build
run: |
npm install
npm run build
- name: Test
run: |
npm test
- name: Validate Semver
id: version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: .github/actions-scripts/validate-release-version.js

- name: Announce version
run: |
echo "v${{ steps.version.outputs.version }} is the proposed new version."
- name: Pack
run: |
npm pack --pack-destination="./umd"
- name: Create Release
uses: actions/github-script@v5
with:
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: 'v${{ steps.version.outputs.version }}',
});
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
npm publish --provenance --access=public
- name: Configure AWS credentials for Prod
id: awskeys
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.CDN_AWS_PUBLISH_ROLE }}
aws-region: ${{ env.AWS_REGION }}

- name: Copy dev build to cdn
run: aws s3 cp umd/embedded.development.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}/

- name: Copy minified build to nonprod cdn
run: aws s3 cp umd/embedded.production.min.js s3://${{ env.CDN_BUCKET }}/${{ env.CDN_PATH }}/v${{ steps.version.outputs.value }}/

10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.11.1](https://github.com/hellosign/hellosign-embedded/compare/v2.11.0...v2.11.1) (2023-07-18)
## [2.11.2](https://github.com/hellosign/hellosign-embedded/compare/v2.11.1...v2.11.2) (2023-12-XX)

### Features

* github actions replaces travis for ci/cd operations. Sign REF: SPDE-130

## [2.11.1](https://github.com/hellosign/hellosign-embedded/compare/v2.11.0...v2.11.1) (2023-07-18)

## [2.11.0](https://github.com/hellosign/hellosign-embedded/compare/v2.10.0...v2.11.0) (2023-07-18)

Expand All @@ -18,12 +24,10 @@ All notable changes to this project will be documented in this file. See [standa

## [2.10.0](https://github.com/hellosign/hellosign-embedded/compare/v2.9.0...v2.10.0) (2021-05-18)


### Features

* Update node-sass and sass-loader ([0234daf](https://github.com/hellosign/hellosign-embedded/commit/0234daf5d9a8654df0313ae95b42eb56220cff23))


### Bug Fixes

* Do not use self-closing tags in HTML markup ([9520b39](https://github.com/hellosign/hellosign-embedded/commit/9520b39f19fbe86c74d94fa3c331cee5a9cf064c))
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# All merges to protected branches (develop & master as of this writing)

* @hellosign/devs-and-devops
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"tiny-emitter": "^2.1.0"
},
"devDependencies": {
"@actions/github": "^6.0.0",
"@actions/github": "^5.1.1",
"@actions/core": "^1.10.1",
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.3.0",
Expand All @@ -57,13 +57,13 @@
"jest-runner-eslint": "^0.7.3",
"node-sass": "^6.0.0",
"sass-loader": "^5.0.0",
"semver": "^7.5.4",
"standard-version": "^9.0.0",
"style-loader": "^0.23.1",
"url-polyfill": "^1.1.8",
"url-search-params-polyfill": "^5.0.0",
"webpack": "^4.29.4",
"webpack-cli": "^3.2.3",
"semver": "^7.5.4"
"webpack-cli": "^3.2.3"
},
"files": [
"umd",
Expand Down

0 comments on commit a7876e9

Please sign in to comment.