Skip to content

Commit f930b9b

Browse files
authored
[other] ENGMT-1857: add gha for release (#1083)
# Pull Request Template ## Description Uses the github release version as the source of truth, this is what we do in our other repositories. Updates the package.json and various configs with the proper version. This means that the new versions will not be checked into the repo, but they will be deployed properly. I am not sure if that is problematic Removes checking in the build.js and build.min.js in favor of always having it built at runtime then deployed Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Unit test - [ ] Integration test ## JS Budget Check Please mention the size in kb before abd after this PR | Files | Before | After | | ----------- | ----------- | ----------- | | dist/build.js. | | | | dist/build.min.js| | | ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules - [ ] I have checked my code and corrected any misspellings ## Mentions: List the person or team responsible for reviewing proposed changes. cc @BranchMetrics/saas-sdk-devs for visibility.
1 parent 9fe08bb commit f930b9b

File tree

14 files changed

+166
-3798
lines changed

14 files changed

+166
-3798
lines changed

.github/workflows/build-push.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16+
- name: Add INPUT_SHA env var
17+
run: |
18+
export INPUT_SHA=$(git rev-parse ${{ github.event.inputs.ref }})
19+
echo "INPUT_SHA=`echo $INPUT_SHA`" >> $GITHUB_ENV
20+
1621
- name: Install Node ${{ env.NODE_VERSION }}
1722
uses: actions/setup-node@v3
1823
with:
@@ -67,6 +72,29 @@ jobs:
6772
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6873
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6974

75+
- name: Get next release version
76+
if: ${{ github.ref == 'refs/heads/master' }}
77+
uses: actions/github-script@v7
78+
id: next-version
79+
with:
80+
result-encoding: string
81+
script: |
82+
const getNextVersion = require('./.branch-github-actions/custom-scripts/next-version');
83+
const nextVersion = await getNextVersion({
84+
core,
85+
github,
86+
context,
87+
sha: process.env.INPUT_SHA,
88+
});
89+
return nextVersion;
90+
env:
91+
INPUT_SHA: ${{ env.INPUT_SHA }}
92+
93+
- name: Write version to files
94+
if: ${{ github.ref == 'refs/heads/master' }}
95+
run: |
96+
./deployment/write-versions.sh ${{ steps.next-version.outputs.result }}
97+
7098
- name: Deploy updated builds to staging
7199
if: ${{ github.ref == 'refs/heads/master' }}
72100
id: build
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish Next Release (Manual)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: Reference git commit to release (e.g. "master", "12341fa")
8+
required: true
9+
default: master
10+
11+
env:
12+
NODE_VERSION: 18
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.event.inputs.ref }}
21+
22+
- name: AWS, credentials setup
23+
uses: aws-actions/configure-aws-credentials@v4
24+
with:
25+
aws-region: us-west-1
26+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
29+
- name: Add INPUT_SHA env var
30+
run: |
31+
export INPUT_SHA=$(git rev-parse ${{ github.event.inputs.ref }})
32+
echo "INPUT_SHA=`echo $INPUT_SHA`" >> $GITHUB_ENV
33+
34+
- name: Install branch-github-actions
35+
uses: actions/checkout@v4
36+
with:
37+
repository: BranchMetrics/branch-github-actions
38+
ref: master
39+
path: .branch-github-actions
40+
token: ${{ secrets.BRANCHLET_ACCESS_TOKEN }}
41+
42+
- name: Get next release version
43+
uses: actions/github-script@v7
44+
id: next-version
45+
with:
46+
result-encoding: string
47+
script: |
48+
const getNextVersion = require('./.branch-github-actions/custom-scripts/next-version');
49+
const nextVersion = await getNextVersion({
50+
core,
51+
github,
52+
context,
53+
sha: process.env.INPUT_SHA,
54+
});
55+
return nextVersion;
56+
env:
57+
INPUT_SHA: ${{ env.INPUT_SHA }}
58+
59+
- name: Install Node ${{ env.NODE_VERSION }}
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: ${{ env.NODE_VERSION }}
63+
64+
- name: Write version to files
65+
run: |
66+
./deployment/write-versions.sh ${{ steps.next-version.outputs.result }}
67+
68+
- name: Configure NPM
69+
run: npm ci
70+
71+
- name: Release to npm, s3, prod
72+
run: |
73+
./deployment/release.sh ${{ steps.next-version.outputs.result }}
74+
75+
- name: Create Github Release
76+
uses: actions/github-script@v7
77+
env:
78+
GE_NEXT_VERSION: ${{ steps.next-version.outputs.result }}
79+
INPUT_SHA: ${{ env.INPUT_SHA }}
80+
with:
81+
result-encoding: string
82+
script: |
83+
const createRelease = require('./.branch-github-actions/custom-scripts/create-release');
84+
const sha = process.env.INPUT_SHA;
85+
const version = process.env.GE_NEXT_VERSION;
86+
await createRelease({
87+
core,
88+
context,
89+
github,
90+
sha,
91+
version,
92+
});

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ test-results.json
3939
.direnv/
4040
dev.config
4141
dev.html
42-
example.html
42+
example.html
43+
dist/

deployment/deploy-qa.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ NC='\033[0m'
2424
./deployment/build-example-html.sh "key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv" "https://api.stage.branch.io" "https://cdn.branch.io/branch-staging-latest.min.js"
2525
aws s3 cp example.html s3://branch-cdn/example-staging.html
2626

27-
./deployment/build-example-html.sh "key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB" "https://api2.branch.io" "https://cdn.branch.io/branch-latest.min.js"
28-
aws s3 cp example.html s3://branch-builds/web-sdk/example.html
29-
3027
echo -en "${GREEN}Pushing to CDN ...${NC}\n"
3128
aws s3 cp --content-type="text/javascript" --content-encoding="gzip" dist/build.min.js.gz s3://branch-cdn/branch-staging-latest.min.js --cache-control "max-age=300"
3229

3330
echo -en "Invalidating cloudfront distribution for staging ...\n"
3431
aws configure set preview.cloudfront true
3532
aws cloudfront create-invalidation --distribution-id E10P37NG0GMER --paths /branch-staging-latest.min.js /example-staging
33+
3634
# Exit prompts
3735
echo -en "${GREEN}Done deploy QA script ...${NC}\n"

deployment/deploy.sh

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

deployment/release.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
[ $# -eq 0 ] && { echo "Usage: $0 1.0.0"; exit 1; }
4+
5+
VERSION_NO_V=$1
6+
VERSION="v"$VERSION_NO_V
7+
DATE=$(date "+%Y-%m-%d")
8+
9+
echo "Releasing Branch Web SDK"
10+
11+
make release
12+
13+
./deployment/build-example-html.sh "key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB" "https://api2.branch.io" "https://cdn.branch.io/branch-latest.min.js"
14+
aws s3 cp example.html s3://branch-builds/example.html
15+
16+
aws s3 cp --content-type="text/javascript" --content-encoding="gzip" dist/build.min.js.gz s3://branch-cdn/branch-$VERSION.min.js --acl public-read
17+
aws s3 cp --content-type="text/javascript" --content-encoding="gzip" dist/build.min.js.gz s3://branch-cdn/branch-latest.min.js --acl public-read
18+
19+
echo -en "Invalidating cloudfront distribution...\n"
20+
aws configure set preview.cloudfront true
21+
aws cloudfront create-invalidation --distribution-id E10P37NG0GMER --paths /branch-latest.min.js
22+
23+
npm publish
24+
25+
echo "Post-release sanity checks."
26+
read -p "Can you visit https://cdn.branch.io/branch-$VERSION.min.js ?" -n 1 -r
27+
echo
28+
read -p "Is https://cdn.branch.io/example.html using the right version number $VERSION?" -n 1 -r
29+
echo
30+
read -p "Is https://www.npmjs.com/package/branch-sdk using the right version number $VERSION?" -n 1 -r
31+
echo

deployment/write-versions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
[ $# -eq 0 ] && { echo "Usage: $0 1.0.0"; exit 1; }
4+
5+
sed -i -e "s/\"version\":.*$/\"version\": \"$1\",/" package.json
6+
sed -i -e "s/version = '.*';$/version = '$1';/" src/0_config.js
7+
sed -i -e "s/version = '.*';$/version = '$1';/" test/web-config.js

0 commit comments

Comments
 (0)