From 87f9e3101f9d201c4f153485837957f3e2f4aa30 Mon Sep 17 00:00:00 2001 From: peterdeme Date: Thu, 21 Apr 2022 18:13:55 +0200 Subject: [PATCH] feat: general maintenance of ci/cd --- .eslintignore | 1 + .github/actions/setup-node/action.yml | 5 +- .github/workflows/browser.yml | 2 +- .github/workflows/cloud.yml | 2 +- .github/workflows/initiate_release.yml | 68 ++++++++++++++++++++++++++ .github/workflows/integration.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 42 ++++++++++++++++ .github/workflows/size.yml | 4 +- .github/workflows/type.yml | 2 +- .github/workflows/unit.yml | 2 +- README.md | 41 +++++++++++----- assets/logo.svg | 16 ++++++ scripts/get_changelog_diff.js | 26 ++++++++++ 14 files changed, 193 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/initiate_release.yml create mode 100644 .github/workflows/release.yml create mode 100644 assets/logo.svg create mode 100644 scripts/get_changelog_diff.js diff --git a/.eslintignore b/.eslintignore index 8ceb4255..c316d0b6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,4 @@ test/integration/utils/kjur.js /.git/ /docs/ **/*.sh +get_changelog_diff.js diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 69c865e6..b10f7d65 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -10,15 +10,16 @@ runs: using: 'composite' steps: - name: Setup Node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ inputs.node-version }} - name: Cache Dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ./node_modules key: ${{ runner.os }}-${{ inputs.node-version }}-modules-${{ hashFiles('**/yarn.lock') }} restore-keys: ${{ runner.os }}-${{ inputs.node-version }}-modules- + - name: Install Dependencies & Build run: yarn install --frozen-lockfile --ignore-engines shell: bash diff --git a/.github/workflows/browser.yml b/.github/workflows/browser.yml index 834d36f2..b76e4b74 100644 --- a/.github/workflows/browser.yml +++ b/.github/workflows/browser.yml @@ -10,7 +10,7 @@ jobs: browser: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node - name: Test env: diff --git a/.github/workflows/cloud.yml b/.github/workflows/cloud.yml index 7116202f..c00d18e9 100644 --- a/.github/workflows/cloud.yml +++ b/.github/workflows/cloud.yml @@ -10,7 +10,7 @@ jobs: qa: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node - name: Test env: diff --git a/.github/workflows/initiate_release.yml b/.github/workflows/initiate_release.yml new file mode 100644 index 00000000..3f5d21ee --- /dev/null +++ b/.github/workflows/initiate_release.yml @@ -0,0 +1,68 @@ +name: Create release PR + +on: + workflow_dispatch: + inputs: + version: + description: "The new version number with 'v' prefix. Example: v1.40.1" + required: true + +jobs: + init_release: + name: ๐Ÿš€ Create release PR + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # gives the changelog generator access to all previous commits + + - name: Get current tag + id: previoustag + uses: WyriHaximus/github-action-get-previous-tag@v1 + + - name: Ensure version number higher than current + uses: actions/github-script@v5 + env: + PREVIOUS_TAG: ${{ steps.previoustag.outputs.tag }} + DESTINATION_TAG: ${{ github.event.inputs.version }} + with: + script: | + const { PREVIOUS_TAG, DESTINATION_TAG } = process.env; + const result = DESTINATION_TAG.localeCompare(PREVIOUS_TAG, undefined, { numeric: true, sensitivity: 'base' }) + + if (result != 1) { + throw new Error('The new version number must be greater than the previous one.') + } + + - name: Restore dependencies + uses: ./.github/actions/setup-node + + - name: Update CHANGELOG.md, package.json and push release branch + env: + VERSION: ${{ github.event.inputs.version }} + run: | + npm run changelog + git config --global user.name 'github-actions' + git config --global user.email 'release@getstream.io' + git checkout -q -b "release-$VERSION" + git commit -am "chore(release): $VERSION" + git push -q -u origin "release-$VERSION" + + - name: Get changelog diff + uses: actions/github-script@v5 + with: + script: | + const get_change_log_diff = require('./scripts/get_changelog_diff.js') + core.exportVariable('CHANGELOG', get_change_log_diff()) + + - name: Open pull request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create \ + -t "chore(release): ${{ github.event.inputs.version }}" \ + -b "# :rocket: ${{ github.event.inputs.version }} + Make sure to use squash & merge when merging! + Once this is merged, another job will kick off automatically and publish the package. + # :memo: Changelog + ${{ env.CHANGELOG }}" diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4b24b855..7c14ea2d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -10,7 +10,7 @@ jobs: integration: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node - name: Test env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4467a6b2..95e9e2b4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node - name: Lint run: yarn run lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2f463462 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release + +on: + pull_request: + types: [closed] + branches: + - main + +jobs: + Release: + name: ๐Ÿš€ Release + if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/github-script@v5 + with: + script: | + const get_change_log_diff = require('./scripts/get_changelog_diff.js') + core.exportVariable('CHANGELOG', get_change_log_diff()) + + // Getting the release version from the PR source branch + // Source branch looks like this: release-1.0.0 + const version = context.payload.pull_request.head.ref.split('-')[1] + core.exportVariable('VERSION', version) + + - uses: ./.github/actions/setup-node + + - name: Publish package + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create release on GitHub + uses: ncipollo/release-action@v1 + with: + body: ${{ env.CHANGELOG }} + tag: ${{ env.VERSION }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml index 73ce9dab..7682715b 100644 --- a/.github/workflows/size.yml +++ b/.github/workflows/size.yml @@ -12,8 +12,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: preactjs/compressed-size-action@v2.0.1 + - uses: actions/checkout@v3 + - uses: preactjs/compressed-size-action@v2 with: repo-token: '${{ secrets.GITHUB_TOKEN }}' build-script: 'dist' diff --git a/.github/workflows/type.yml b/.github/workflows/type.yml index bf67a129..03577b72 100644 --- a/.github/workflows/type.yml +++ b/.github/workflows/type.yml @@ -10,7 +10,7 @@ jobs: types: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node - name: Type check run: yarn run types diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index a8df5786..1f866712 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -13,7 +13,7 @@ jobs: matrix: node: [12, 14, 16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-node with: node-version: ${{ matrix.node }} diff --git a/README.md b/README.md index 8ef168b5..c2bfd0a8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,33 @@ -# Stream-JS - -[![build](https://github.com/GetStream/stream-js/workflows/build/badge.svg)](https://github.com/GetStream/stream-js/actions) +# Official JavaScript SDK for [Stream Feeds](https://getstream.io/activity-feeds/) +[![build](https://github.com/GetStream/stream-js/workflows/build/badge.svg)](https://github.com/GetStream/stream-js/actions) [![NPM](https://nodei.co/npm/getstream.png)](https://nodei.co/npm/getstream/) +

+ +

+

+ Official JavaScript API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams. +
+ Explore the docs ยป +
+
+ Report Bug + ยท + Request Feature +

+ +## ๐Ÿ“ About Stream + [stream-js](https://github.com/GetStream/stream-js) is the official JavaScript client for [Stream](https://getstream.io/), a web service for building scalable newsfeeds and activity streams. Note that there is also a [higher level Node integration](https://github.com/getstream/stream-node-orm) which hooks into your ORM. You can sign up for a Stream account at https://getstream.io/get_started. -### Installation +## โš™๏ธ Installation -#### Install from NPM/YARN +### Install from NPM/YARN ```bash npm install getstream @@ -36,14 +51,14 @@ yarn add getstream ``` -#### Install by downloading the JS file +### Install by downloading the JS file [JS](https://raw.githubusercontent.com/GetStream/stream-js/main/dist/js/getstream.js) / [Minified JS](https://raw.githubusercontent.com/GetStream/stream-js/main/dist/js_min/getstream.js) > :warning: Beware about the version you're pulling. It's the latest by default which can break your app anytime. -### Full documentation +## ๐Ÿ“š Full documentation Documentation for this JavaScript client are available at the [Stream website](https://getstream.io/docs/?language=js). @@ -51,7 +66,7 @@ Documentation for this JavaScript client are available at the [Stream website](h This package can be integrated into React Native applications. Remember to not expose the App Secret in browsers, "native" mobile apps, or other non-trusted environments. -### Usage +## โœจ Getting started ### API client setup Node @@ -359,15 +374,15 @@ subscription.cancel(); Docs are available on [GetStream.io](http://getstream.io/docs/?language=js). -#### Node version requirements & Browser support +## โš ๏ธ Node version requirements & Browser support This API Client project requires Node.js v10 at a minimum. The project is supported in line with the Node.js Foundation Release Working Group. -See the [github action configuration](.github/workflows/ci.yml) for details of how it is built, tested and packaged. +See the [github action configuration](.github/workflows/) for details of how it is built, tested and packaged. -## Contributing +## โ™ป๏ธ Contributing See extensive at [test documentation](test/README.md) for your changes. @@ -377,7 +392,9 @@ You can find generic API documentation enriched by code snippets from this packa Project is licensed under the [BSD 3-Clause](LICENSE). -## We are hiring! +We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details. + +## ๐Ÿง‘โ€๐Ÿ’ป We are hiring! We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world. diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 00000000..1c68c5cc --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,16 @@ + + + + STREAM MARK + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/get_changelog_diff.js b/scripts/get_changelog_diff.js new file mode 100644 index 00000000..425e0f3e --- /dev/null +++ b/scripts/get_changelog_diff.js @@ -0,0 +1,26 @@ +/* +Here we're trying to parse the latest changes from CHANGELOG.md file. +The changelog looks like this: + +## 0.0.3 +- Something #3 +## 0.0.2 +- Something #2 +## 0.0.1 +- Something #1 + +In this case we're trying to extract "- Something #3" since that's the latest change. +*/ +module.exports = () => { + const fs = require('fs'); + + changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); + releases = changelog.match(/## [?[0-9](.+)/g); + + current_release = changelog.indexOf(releases[0]); + previous_release = changelog.indexOf(releases[1]); + + latest_changes = changelog.substr(current_release, previous_release - current_release); + + return latest_changes; +};