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

Github Actions example #540

Open
xhyrom opened this issue Aug 22, 2023 · 6 comments
Open

Github Actions example #540

xhyrom opened this issue Aug 22, 2023 · 6 comments

Comments

@xhyrom
Copy link

xhyrom commented Aug 22, 2023

Hey, i'm trying to setup this with github actions but im stucked on npm credentials.
https://github.com/xHyroM/things/blob/main/.github/workflows/release.yml

I know, its recommended to use https://github.com/jscutlery/semver and i have installed it, but want to figure this out and then somehow merge it. I'm really new using nx and don't know with it so much.

Some example of using github actions would be great and also with jscutlery's semver

@dianjuar
Copy link
Member

Currently, there is an Open Issue to include an example with Github Actions on the readme.

We use semver and ngx-deploy-npm (yes, we are using ourselves to publish our package to NPM). You can always go and see a production like examples of both technologies in action

@dianjuar
Copy link
Member

Quickly analyzing your CI, I would recommend using a reusable action to install your dependencies and use it whenever you need it.

You can take this repo's set-up action as an example.

@xhyrom
Copy link
Author

xhyrom commented Aug 23, 2023

Currently, there is an Open Issue to include an example with Github Actions on the readme.

We use semver and ngx-deploy-npm (yes, we are using ourselves to publish our package to NPM). You can always go and see a production like examples of both technologies in action

I saw this production example, but confused what nx version exactly does. Does it increase semver version by jscutlery's semver and publish to npm?

edit: i see https://github.com/bikecoders/ngx-deploy-npm/blob/main/packages/ngx-deploy-npm/project.json#L71-L77 but its quite confusing that version command also create release to npm. What about monorepo with more packages?

@dianjuar
Copy link
Member

dianjuar commented Aug 28, 2023

Does it increase semver version by jscutlery's semver and publish to npm

Yes. It creates a version and, after that, if there is a new version, tries to publish that version to NPM.

@dianjuar
Copy link
Member

This might help you, a generic project.json with semver and ngx-deploy-npm

{
  "name": "YOUR_LIB_NAME",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "packages/YOUR_LIB_NAME/src",
  "projectType": "library",
  "targets": {
    "deploy": {
      "executor": "ngx-deploy-npm:deploy",
      "options": {
        "access": "public"
      }
    },
    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "postTargets": ["YOUR_LIB_NAME:deploy"],
        "versionTagPrefix": "v"
      }
    }
  },
  "tags": []
}

To publish you must run nx version YOUR_LIB_NAME.

Explanation

To publish a new version, you run the version target. The version target has an option called postTargets, which is what the target will run after the version is created. You might wonder, why do it in that way? the reason is that you might not have a new version to publish every time you run version. When that happens, the version target will not activate the deployment. That is really convenient because if you run the target deploy when there is no version to publish, the target deploy will fail because you are trying to publish an already published version.

For instance, since your last deployment, there are only ci and test commits there is no new version to publish.

@dianjuar
Copy link
Member

What about monorepo with more packages?

What I'm seeing other devs are using is creating the same version target in all the projects, and they run the version target on all the affected projects to verify if the changes make a new version.

The command would be nx affected --target=version

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

No branches or pull requests

2 participants