Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 0c19f08

Browse files
authored
Release @fluencelabs/fluence automatically (#5)
1 parent 1995425 commit 0c19f08

File tree

4 files changed

+163
-5
lines changed

4 files changed

+163
-5
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: "publish-branch"
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
npm-publish:
8+
name: "Publish"
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
steps:
15+
### Extract branch name
16+
- name: Extract branch name
17+
if: github.event_name != 'pull_request'
18+
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
19+
id: extract_branch
20+
21+
- name: Extract branch name
22+
if: github.event_name == 'pull_request'
23+
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
24+
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
28+
### Calculate FINAL_VERSION
29+
- name: Install jq
30+
run: sudo apt-get update && sudo apt-get --yes --force-yes install jq
31+
32+
- name: Get version from npm and increment
33+
run: |
34+
set -x
35+
yarn global add semver
36+
PATH="$(yarn global bin):$PATH"
37+
38+
# take npm version and increment it
39+
PKG_NAME="$(cat package.json | jq -r .name)"
40+
41+
# sanitize branch name so it can be used as a semver suffix (replace [^0-9a-zA-Z-] with hyphen)
42+
SANITIZED_BRANCH="$(echo -n "${{ env.BRANCH_NAME }}" | tr -C '[:alnum:]-' -)"
43+
44+
# take all versions from npm and replace single quotes with double quotes
45+
NPM_VERSIONS=$(yarn info --silent "$PKG_NAME" versions 2>/dev/null | tr \' \")
46+
# take only versions that contain branch name
47+
NPM_VERSIONS_FILTERED=$(echo $NPM_VERSIONS | jq -r ".[] | select(contains(\"$SANITIZED_BRANCH\"))")
48+
# flatten into a single line
49+
NPM_VERSIONS_FLATTENED=$(echo $NPM_VERSIONS_FILTERED | awk '{print}' ORS=' ')
50+
# sort versions according to semver, take highest (last)
51+
LAST_NPM_VERSION="$(semver -p $(echo $NPM_VERSIONS_FLATTENED) | tail -n1 || true)"
52+
# increment prerelease part of the version
53+
PRERELEASE_NPM_VERSION="$(semver --increment prerelease --preid "$SANITIZED_BRANCH" "${LAST_NPM_VERSION}" || true)" # added '-0' here to avoid semver erroneously increment patch octet. Any suffix works, '-0' is chosen deliberately.
54+
55+
# take local version
56+
LOCAL_VERSION="$(cat package.json | jq -r .version)"
57+
# set prerelease part on local version
58+
LOCAL_PRERELEASE_VERSION="$(semver --increment prerelease --preid "$SANITIZED_BRANCH" "${LOCAL_VERSION}-0")" # added '-0' here to avoid semver erroneously increment patch octet. Any suffix works, '-0' is chosen deliberately.
59+
60+
# take the highest version
61+
MAX_VERSION="$(semver "$LOCAL_PRERELEASE_VERSION" "$PRERELEASE_NPM_VERSION" | tail -n1)"
62+
63+
# save info to env
64+
echo "FINAL_VERSION=$MAX_VERSION" | tee -a $GITHUB_ENV
65+
echo "PKG_NAME=$PKG_NAME" | tee -a $GITHUB_ENV
66+
67+
### Set version
68+
- name: Set version to ${{ env.FINAL_VERSION }}
69+
run: yarn version --new-version ${{ env.FINAL_VERSION }} --no-git-tag-version
70+
71+
### Publish to NPM registry
72+
- uses: actions/setup-node@v1
73+
with:
74+
node-version: '15'
75+
registry-url: 'https://registry.npmjs.org'
76+
77+
- run: cat package.json
78+
79+
- run: npm i
80+
- run: npm run build
81+
82+
- run: npm publish --access public
83+
env:
84+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "publish-release"
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
8+
jobs:
9+
npm-publish:
10+
name: "Publish"
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
### Calculate FINAL_VERSION
21+
- name: Install jq
22+
run: sudo apt-get update && sudo apt-get --yes --force-yes install jq
23+
24+
- name: Get version from npm and increment
25+
run: |
26+
set -x
27+
yarn global add semver
28+
PATH="$(yarn global bin):$PATH"
29+
30+
# take npm version and increment it
31+
PKG_NAME="$(cat package.json | jq -r .name)"
32+
NPM_VERSION="$(yarn info --silent "$PKG_NAME" version || true)"
33+
NEXT_NPM_VERSION="$(semver --increment patch "$NPM_VERSION")"
34+
35+
# take local version
36+
LOCAL_VERSION="$(cat package.json | jq -r .version)"
37+
38+
# take maximum of the local and NEXT_NPM versions
39+
MAX_VERSION="$(semver "$LOCAL_VERSION" "$NEXT_NPM_VERSION" "0.0.0" | tail -n1)"
40+
41+
# save info to env
42+
echo "FINAL_VERSION=$MAX_VERSION" | tee -a $GITHUB_ENV
43+
echo "PKG_NAME=$PKG_NAME" | tee -a $GITHUB_ENV"
44+
45+
### Set version
46+
- name: Set version to ${{ env.FINAL_VERSION }}
47+
run: yarn version --new-version ${{ env.FINAL_VERSION }} --no-git-tag-version
48+
49+
### Publish to NPM registry
50+
- uses: actions/setup-node@v1
51+
with:
52+
node-version: '14'
53+
registry-url: 'https://registry.npmjs.org'
54+
55+
- run: npm i
56+
- run: npm run build
57+
58+
- run: npm publish --access public
59+
env:
60+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
61+
62+
### Create a pre-release
63+
- name: Create Release
64+
id: create_release
65+
uses: actions/create-release@v1
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
with:
69+
tag_name: ${{ env.FINAL_VERSION }}
70+
release_name: Fluence Network ${{ env.FINAL_VERSION }}
71+
body: |
72+
[${{ env.FINAL_VERSION }} @ NPM registry](https://www.npmjs.com/package/${{ env.PKG_NAME }}/v/${{ env.FINAL_VERSION }})
73+
draft: false
74+
prerelease: false

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "fluence",
3-
"version": "0.7.108",
4-
"description": "the browser js-libp2p client for the Fluence network",
2+
"name": "@fluencelabs/fluence",
3+
"version": "0.8.0",
4+
"description": "JS SDK for the Fluence network",
55
"main": "./dist/fluence.js",
66
"typings": "./dist/fluence.d.ts",
77
"scripts": {

0 commit comments

Comments
 (0)