Skip to content
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

feat(workspace): Add workspaces to specify build order dependencies in packages. #1004

Merged
merged 22 commits into from
Jul 22, 2023

Conversation

jafin
Copy link
Contributor

@jafin jafin commented Mar 18, 2023

Workspaces

  • Add in npm workspaces to provide order to build dependencies.
  • Move oidc-service-worker up a level outside of packages/react
  • Update workflows with changes to workspaces.
  • Adjust test for each project to be non-watch mode (Added test:watch as replacement). So that pipeline can call test from root and all packages can run test for CI
  • cpy introduced as copyfiles I was having issues with it copying foldernames instead of folder contents.

🐲🐲🐲 NOTE: I have not tested the changes to the workflows, it was a BEST EFFORT approach and will need review.

This should assist in easing the package dependency chain. 👏

Decisions

I looked into lerna and installed it, but it wasn't doing much above what native npm workspaces added. Lerna documentation also notes that they now lean on npm(pnpm/yarn) workspaces (something lerna->bootstrap used to provide). Perhaps there are some other benefits I didn't discover?

Lerna can still be added, it should be a simple update to add it into the root project without much change, and just the various npm workspace commands with lerna equivalent.

@guillaume-chervet
Copy link
Contributor

Thank you again @jafin , that awesome.
learna just automate publishing many packages dependencies. But for the moment this repo is not big enough for it.

Just give me some time to learn abou npm workspace :p

Do you have a twitter account or a linkedin?

@jafin
Copy link
Contributor Author

jafin commented Mar 20, 2023

@guillaume-chervet Sorry I don't have an active Twitter/linked in at the moment.

With respect to publishing, you may also be interested in looking at changeset. When I tested things on my fork of this repo, I setup a github workflow and found it quite easy to perform publishing to npm registry.

One thing I did like with it, was the way you can explicitly trigger a release (still from GitHub web), to allow queueing a set of changes, avoiding minor point releases for every commit to main.

But this would require a change in PR's, to request a user to run a changeset command to enter a description of the change, and if it was a minor/major breaking change etc.

I had a example github workflow here https://github.com/jafin/react-oidc/blob/master/.GitHub/workflows/release.yml It was quite basic though.

@guillaume-chervet
Copy link
Contributor

Very Sorry @jafin for the delay, I'am lacking of times these days .

@jafin jafin marked this pull request as draft April 16, 2023 01:23
@jafin
Copy link
Contributor Author

jafin commented Apr 16, 2023

@guillaume-chervet is all fine, I will need to rework this anyhow after the repo changes, it will be a little while for me to revisit. Changing to draft.

@guillaume-chervet
Copy link
Contributor

hi @jafin , do you want to continue your pullrequest ?
I'am started to really need this :)

@jafin
Copy link
Contributor Author

jafin commented Jul 12, 2023

Hi @guillaume-chervet
Apologies for leaving this hanging.

I can have a look this weekend.

Some questions for you on approach.

As I said above I tried lerna and reverts to npm workspaces as I wasn't seeing a huge benefit from having lerna there.
So I would still perhaps suggest going for npm + workspaces or even pnpm + workspaces.?

Let me know.

@guillaume-chervet
Copy link
Contributor

Hi @jafin ,

I have read more documentation.
npm workspace is perfect.

New lerna version documentation say that learna is compatible with npm workspace.
Learna is not necessary for now. It is just about synchronize packages version for publishing packages. It can be bring after.

Thank you so much for you help.

A little more roadmap information for you. I aim to:

  • add workspaces
  • rename vanilla-oidc to oidc-client
  • make react-oidc depends on oidc-client
  • upgrade documentation to explain more about oidc-client
  • rename repository to oidc-client
  • continue clean code and unit test
  • start exchange for openid certification

@jafin
Copy link
Contributor Author

jafin commented Jul 12, 2023

@guillaume-chervet sounds good!
I'll fix this PR up in the next few days for review.

@guillaume-chervet
Copy link
Contributor

That look awesome @jafin

@jafin
Copy link
Contributor Author

jafin commented Jul 17, 2023

Hi @guillaume-chervet This turned out bigger than I thought.
Would you be able to have a look at it again? I think it should be in a good position to be reviewed.

I haven't made any changes regarding packaging and versioning, so I am unsure if the pipeline scripts need work or amendment.
The workspace dependencies currently use workspace:* references, which should get replaced on pack/publish, but I haven't checked this functionality.

Ideally, it would be highly beneficial if this project could publish betas or alphas to avoid end users being interrupted in the event there are errors. (I have not done anything in regard to versioning with this change)
I assume there will be bugs to iron out.

todo

  • Packaging libraries and ensure versioning of dependencies is correctly set. (instead of workspace) (@guillaume-chervet ? Per the docs https://pnpm.io/workspaces#referencing-workspace-packages-through-aliases
  • react-vite-demo is now almost redundant with react-oidc-demo (which uses vite) Should it be deleted? Or do you see value in maintaining it?
  • You mentioned to rename vanilla-oidc to oidc-client, I have renamed the package folder, but the package name is the same still. I did not want to make that change now as there were already too many things in this PR.

Changes

  • rename vanilla-oidc to oidc-client (did not change pkg name though)
  • move react/src/oidc/vanilla -> oidc-client/src/
  • export getParseQueryStringFromLocation , getPath , getFetchDefault TokenRenewMode from vanilla.
  • jsxnext:main replaced with module (https://www.reddit.com/r/javascript/comments/5jwg9c/confused_about_fields_module_and_jsnextmain_in/) in package.json
  • replace copyfiles with cpy (just to standardise, and cpy seems the dominant used pkg)
  • separate the react-oidc-demo code moved to examples/react-oidc-demo/ from the react-oidc client package.
  • migrate cra apps to vite
  • add a basic build/test CI pipeline, it could run on each PR/commit as a lightweight check.
  • Update to typescript 5. Change some of the exports to export type

Issues Encountered

Postinstall scripts put in wrong folder

Running the demo projects, but issuing pnpm i from root not from project folder, will place the service-worker files in the wrong folder (root/public) rather than the demo/public folder.

If you run pnpm i from the root, then the postinstall sripts treat the execution path, root, as the destination to copy script to /public. Which then stops the demo from having the service worker scripts in the correct place.

The work around, is to run pnpm i from the demo project folder, and the post-install script will copy the file into the correct /public folder. Perhaps this can be improved in future to be more robust no matter where pnpm i is triggered. Perhaps document so other developers note the question.

Future improvements (beyond this pr)

  • Share tslint configurations by pulling up a folder
  • Share prettier configurations by pulling up to parent folder.
  • add nx for performance.
  • ability to run script commands from root, such as build/test that run recursively.
  • Can the postDeploy script be made more robust?
  • Does it make sense to create a package for the service worker? This may avoid the postinstall script magic in the react-oidc and oidc-client libraries, they could just have a dependency on the service-worker package?
  • Review build pipeline, are there optimizations to be done there, such as caching. Perhaps align this with nx.

@jafin jafin marked this pull request as ready for review July 17, 2023 14:21
@guillaume-chervet
Copy link
Contributor

So awesome @jafin , i test it tomorrow and i will prepare a branch that can publish alpha version to test it.

@@ -5,9 +5,9 @@ name: React Oidc CI

on:
Copy link
Contributor

@guillaume-chervet guillaume-chervet Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jafin
May you set up the file like bellow.
I do knot know if it work but it will allow to publish alpha directly from "alpha" GIT branch in order to test.

  • I have updated how next version compute
  • I set up publish of oidc-lient before react-oidc
  • set up publish from alpha branch
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: React Oidc CI

on:
  push:
    branches: [ main, alpha ]
  pull_request:
    branches: [ main, alpha ]

jobs:
  skip_ci:
    runs-on: ubuntu-latest
    outputs:
      canSkip: ${{ steps.check.outputs.canSkip }}
    steps:
      - id: check
        uses: Legorooj/skip-ci@main
  tests:
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
        with:
          node-version: 18

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8.5.1
          run_install: false          

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

  build:
    environment: react-oidc
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && !github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GIT_TOKEN }}

      - name: Bump version and push tag
        id: tag_version
        if: github.ref == 'refs/heads/main'
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
      - name: Bump version and push tag
        id: tag_version
        if: github.ref == 'refs/heads/alpha'
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
          dry_run: true
      - name: Add tag to output step for main branch
        id: tag
        run: |
          if [ '${{ github.ref }}' = 'refs/heads/main' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT
          else
            echo "new_version=${{ steps.tag_version.outputs.new_version }}-alpha${{ github.run_number }}" >> $GITHUB_OUTPUT
          fi
      
      - uses: actions/setup-node@v2
        with:
          node-version: 18

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8.5.1
          run_install: false          
      
      # Oidc Client
      - name: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha'
        run: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/oidc-client

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

      - id: publish-oidc-client
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main'
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/oidc-client/package.json
          
      # React Oidc
      - name: npm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha'
        run: npm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/react-oidc

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - id: publish-react
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main'
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/react-oidc/package.json

      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.head.repo.fork
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          args: >
            -Dsonar.organization=axaguildev
            -Dsonar.projectKey=AxaGuilDEv_react-oidc
            -Dsonar.exclusions=**/*.spec.js,**/*.stories.js,Scripts/**,**/*.scss,**/__snapshots__/**,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts
            -Dsonar.javascript.lcov.reportPaths=**/coverage/lcov.info
            
      - name: Commit updates package.json
        uses: stefanzweifel/git-auto-commit-action@v4
        if: github.ref == 'refs/heads/main'
        with:
          commit_message: "[skip ci] Update version package.json"
          commit_user_name: GitHub
          commit_user_email: github-action@bot.com
          commit_author: GitHub <github-action@bot.com>
          push_options: '--force'

      - name: Create a GitHub release
        uses: ncipollo/release-action@v1
        if: github.ref == 'refs/heads/main'
        with:
          tag: ${{ steps.tag_version.outputs.new_tag }}
          name: Release ${{ steps.tag_version.outputs.new_tag }}
          body: ${{ steps.tag_version.outputs.changelog }}

readme.md Outdated Show resolved Hide resolved
@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Jul 18, 2023

Thank you so much @jafin .
This PullRequest is a huge and excelent Job.
I have created a alpha branch. The idea is that a merge to alpha branch will publish an alpha automaticaly.

I have tested demo and they all works !

@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Jul 18, 2023

From your questions,

  • I think, yes, I'am agree vite demo is rededondant and can be deleted.
  • I think service-worker package you set up make sense. From my first point of view It appear cleanner from before. It seems easier to understand how it works. I like it.

@jafin
Copy link
Contributor Author

jafin commented Jul 18, 2023

Thank you so much @jafin . This PullRequest is a huge and excelent Job. I have created a alpha branch. The idea is that a merge to alpha branch will publish an alpha automaticaly.

I have tested demo and they all works !

THank you @guillaume-chervet , I think having the option to release test builds before new official version may ensure bugs are fixed before a new official version rolls out. Just a comment, the way you have it setup now in this repo, aligns with github-flow, single branch for deploys makes it simple and quick to do always ready releases. I didn't want to complicate that with other branches, sorry for the misunderstanding. Just a way to push to main without an official release being created, perhaps if the CI is able to release a beta via tagging rather than always create new release on PR push to main, that would be great, and avoid having unnecessary branches. And still adhering to the github-flow approach

One option could be each PR merged to main, this triggers a new beta-release. To create an official release, manually tag main? But if this introduces too much overhead I understand.

Thank you for reviewing the changes. I'll update the changes you mentioned above and notify when done.

@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Jul 19, 2023

Thank you again @jafin , you force me to find a better solution.

I do not like manual tag because it is too manual. Too many actions.

Here an idea of a solution, continue to use last git commit comment and automate everything.

  • feat(oidc): my message (alpha) => will publish next minor as an alpha
  • feat(oidc): my message (beta) => will publish next minor as an beta
  • feat(oidc): my message (release) => will publish next minor release (with automatic git tag and release)

With the script bellow (not tested). It is more intricate, but I think workflow would be simpler.

What do you think about ?

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: React Oidc CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  skip_ci:
    runs-on: ubuntu-latest
    outputs:
      canSkip: ${{ steps.check.outputs.canSkip }}
    steps:
      - id: check
        uses: Legorooj/skip-ci@main
  tests:
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
        with:
          node-version: 18

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8.5.1
          run_install: false

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

  build:
    environment: react-oidc
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && !github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GIT_TOKEN }}
      - name: Determine Alpha, Beta or Release
        id: which_tag
        run: |
          last_commit_message=$(git log --format=%B -n 1)
          # Check if last comment and with "(alpha)"
          if [[ $last_commit_message == *"(alpha)" ]]; then
            echo "tag=alpha" >> $GITHUB_OUTPUT
          fi
          if [[ $last_commit_message == *"(beta)" ]]; then
            echo "tag=beta" >> $GITHUB_OUTPUT
          fi
          if [[ $last_commit_message == *"(release)" ]]; then
            echo "tag=release" >> $GITHUB_OUTPUT
          fi

      - name: Bump version and push tag
        id: tag_version
        if: which_tag.ref == 'refs/heads/main' && steps.which_tag.outputs.tag == 'release'
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
      - name: Bump version and push tag
        id: tag_version
        if: which_tag.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
          dry_run: true
      - name: Add tag to output step for main branch
        id: tag
        run: |
          if [ '${{ github.ref }}' = 'refs/heads/main' && steps.which_tag.outputs.tag = 'release' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT
          fi
          if [ '${{ github.ref }}' = 'refs/heads/main' && (steps.which_tag.outputs.tag = 'alpha' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}-alpha${{ github.run_number }}" >> $GITHUB_OUTPUT
          fi
          if [ '${{ github.ref }}' = 'refs/heads/main' && (steps.which_tag.outputs.tag = 'beta' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}-beta${{ github.run_number }}" >> $GITHUB_OUTPUT
          fi

      - uses: actions/setup-node@v2
        with:
          node-version: 18

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8.5.1
          run_install: false
      
      # Oidc Client
      - name: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        run: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/oidc-client

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

      - id: publish-oidc-client
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/oidc-client/package.json
      
      # React Oidc
      - name: npm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        run: npm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/react-oidc

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - id: publish-react
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/react-oidc/package.json

      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.head.repo.fork
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          args: >
            -Dsonar.organization=axaguildev
            -Dsonar.projectKey=AxaGuilDEv_react-oidc
            -Dsonar.exclusions=**/*.spec.js,**/*.stories.js,Scripts/**,**/*.scss,**/__snapshots__/**,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts
            -Dsonar.javascript.lcov.reportPaths=**/coverage/lcov.info

      - name: Commit updates package.json
        uses: stefanzweifel/git-auto-commit-action@v4
        if: github.ref == 'refs/heads/main'
        with:
          commit_message: "[skip ci] Update version package.json"
          commit_user_name: GitHub
          commit_user_email: github-action@bot.com
          commit_author: GitHub <github-action@bot.com>
          push_options: '--force'

      - name: Create a GitHub release
        uses: ncipollo/release-action@v1
        if: github.ref == 'refs/heads/main'
        with:
          tag: ${{ steps.tag_version.outputs.new_tag }}
          name: Release ${{ steps.tag_version.outputs.new_tag }}
          body: ${{ steps.tag_version.outputs.changelog }}

@jafin
Copy link
Contributor Author

jafin commented Jul 19, 2023

Here an idea of a solution, continue to use last git commit comment and automate everything.

  • feat(oidc): my message (alpha) => will publish next minor as an alpha
  • feat(oidc): my message (beta) => will publish next minor as an beta
  • feat(oidc): my message (release) => will publish next minor release (with automatic git tag and release)

With the script bellow (not tested). It is more intricate, but I think workflow would be simpler.

What do you think about ?

I don't have a strong opinion, perhaps try it and see how it works.
It sounds a bit like https://github.com/googleapis/release-please

Also, I have updated the PR with the fixes you highlighted.

@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Jul 19, 2023

Yes @jafin , let's try like this.
Do you want i update CI build from another PullRequest and after merge or do you to merge your PullRequest in this state?
And again thabk you so much for your awesome work.

@jafin
Copy link
Contributor Author

jafin commented Jul 19, 2023

@guillaume-chervet sure if you can update the CI first, then I'll rebase onto the changes for this PR. Or feel free to amend it as part of this change. Whatever is easiest for you.

@jafin
Copy link
Contributor Author

jafin commented Jul 20, 2023

@guillaume-chervet

Some suggested changes.

  • id: must be unique, changed tag_version for release to tag_release (I assume running the tag-action twice is ok?)
  • drop condition on tag_version so it runs for all versions (but still with dryrun)
  • missing steps. on line ~81/86 if condition (if: steps.which_tag.ref )
  • globally set node/pnpm version env
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: React Oidc CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  PNPM_VERSION: 8.5.1
  NODE_VERSION: 18

jobs:
  skip_ci:
    runs-on: ubuntu-latest
    outputs:
      canSkip: ${{ steps.check.outputs.canSkip }}
    steps:
      - id: check
        uses: Legorooj/skip-ci@main
  tests:
    needs: skip_ci
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: ${{ env.PNPM_VERSION }}
          run_install: false

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

  build:
    needs: skip_ci
    environment: react-oidc
    runs-on: ubuntu-latest
    if: needs.skip_ci.outputs.canSkip != 'true' && !github.event.pull_request.head.repo.fork
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GIT_TOKEN }}
      - name: Determine Alpha, Beta or Release
        id: which_tag
        run: |
          last_commit_message=$(git log --format=%B -n 1)
          # Check if last comment and with "(alpha)"
          if [[ $last_commit_message == *"(alpha)" ]]; then
            echo "tag=alpha" >> $GITHUB_OUTPUT
          fi
          if [[ $last_commit_message == *"(beta)" ]]; then
            echo "tag=beta" >> $GITHUB_OUTPUT
          fi
          if [[ $last_commit_message == *"(release)" ]]; then
            echo "tag=release" >> $GITHUB_OUTPUT
          fi

      - name: Bump version and push tag
        id: tag_release
        if: steps.which_tag.ref == 'refs/heads/main' && steps.which_tag.outputs.tag == 'release'
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
      - name: Bump version and push tag
        id: tag_version
        uses: mathieudutour/github-tag-action@v6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN  }}
          dry_run: true
      - name: Add tag to output step for main branch
        id: tag
        run: |
          if [ '${{ github.ref }}' = 'refs/heads/main' && steps.which_tag.outputs.tag = 'release' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT
          fi
          if [ '${{ github.ref }}' = 'refs/heads/main' && (steps.which_tag.outputs.tag = 'alpha' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}-alpha${{ github.run_number }}" >> $GITHUB_OUTPUT
          fi
          if [ '${{ github.ref }}' = 'refs/heads/main' && (steps.which_tag.outputs.tag = 'beta' ]; then
            echo "new_version=${{ steps.tag_version.outputs.new_version }}-beta${{ github.run_number }}" >> $GITHUB_OUTPUT
          fi

      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: ${{ env.PNPM_VERSION }}
          run_install: false
      
      # Oidc Client
      - name: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        run: pnpm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/oidc-client

      - name: pnpm install
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/oidc-client

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/oidc-client

      - id: publish-oidc-client
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/oidc-client/package.json
      
      # React Oidc
      - name: npm version ${{ steps.tag_version.outputs.new_tag }}
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        run: npm version ${{ steps.tag_version.outputs.new_tag }}
        working-directory: ./packages/react-oidc

      - name: pnpm i
        run: pnpm i --frozen-lockfile
        working-directory: ./packages/react-oidc

      - name: pnpm prepare
        run: pnpm run prepare
        working-directory: ./packages/react-oidc

      - name: pnpm test
        run: pnpm test -- --run
        working-directory: ./packages/react-oidc

      - id: publish-react
        uses: JS-DevTools/npm-publish@v1
        if: github.ref == 'refs/heads/main' && (steps.which_tag.outputs.tag == 'release' || steps.which_tag.outputs.tag == 'alpha' || steps.which_tag.outputs.tag == 'beta')
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./packages/react-oidc/package.json

      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.head.repo.fork
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          args: >
            -Dsonar.organization=axaguildev
            -Dsonar.projectKey=AxaGuilDEv_react-oidc
            -Dsonar.exclusions=**/*.spec.js,**/*.stories.js,Scripts/**,**/*.scss,**/__snapshots__/**,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts
            -Dsonar.javascript.lcov.reportPaths=**/coverage/lcov.info

      - name: Commit updates package.json
        uses: stefanzweifel/git-auto-commit-action@v4
        if: github.ref == 'refs/heads/main'
        with:
          commit_message: "[skip ci] Update version package.json"
          commit_user_name: GitHub
          commit_user_email: github-action@bot.com
          commit_author: GitHub <github-action@bot.com>
          push_options: '--force'

      - name: Create a GitHub release
        uses: ncipollo/release-action@v1
        if: github.ref == 'refs/heads/main'
        with:
          tag: ${{ steps.tag_version.outputs.new_tag }}
          name: Release ${{ steps.tag_version.outputs.new_tag }}
          body: ${{ steps.tag_version.outputs.changelog }}

@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Jul 20, 2023

hi @jafin,

I really struggle to do it.

It does not work with your last advice. It works on it:
#1099

jafin added 22 commits July 21, 2023 23:21
- Move packages/nextjs-demo to examples/nextjs-demo
- Move packages/oidc-client-demo to examples/
- Isolate/Extract react-oidc-demo from packages/react into examples/react-oidc-demo
  - Update imports to reference @axa-fr/react-oidc instead of relative path

- Setup workspaces in root
- build with pnpm
- Adjust post install script logic, rename to post-install.(m)js
- Extract oidc-service-worker into own package
- Configure monorepo dependencies to use `workspace` references internally.

- replace craco/cra with vite
- Add exports to vanilla-oidc to allow imports from react-oidc.
- similar functionality exists in react-oidc-demo
@jafin
Copy link
Contributor Author

jafin commented Jul 21, 2023

Thanks @guillaume-chervet , merged.

@guillaume-chervet
Copy link
Contributor

Thank you so much @jafin

@guillaume-chervet
Copy link
Contributor

Which kind of merge do you prefer @jafin .
Again thank you so much

@jafin
Copy link
Contributor Author

jafin commented Jul 22, 2023

@guillaume-chervet just squash it I think.

@guillaume-chervet guillaume-chervet merged commit 4be9aed into AxaFrance:main Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants