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

Add reusable GitHub workflows "lint & tests" and "tag & publish" for JS projects #2

Merged
merged 6 commits into from
Nov 2, 2021

Conversation

MrChocolatine
Copy link
Contributor

@MrChocolatine MrChocolatine commented Oct 29, 2021

Add a reusable GitHub workflow "lint & tests" for Ember.js add-ons (#2)

This reusable workflow runs the typical jobs that Ember.js add-ons should run (as already implemented in ember-cli-embedded) to lint and test their codebase.

It accepts 3 inputs from the caller workflow1:

  • ember_try_scenarios (optional)
    A list of test scenarios to run with ember-try,
    If not specified, a predefined list of scenarios will be used.

    This can be used, for instance, to force ember-try not to run Embroider scenarios when it is not yet installed in the add-on. (see an example)

  • nodejs_version (optional)
    The version of Node.js to use.
    If not specified, the version 12 will be used (which is still a LTS for the moment)

  • package_manager (optional)
    Which package manager to use between npm and yarn.
    If not specified, yarn will be used.

One information, the step Lint lockfile is a custom addition in order to spot eventual malicious attacks (see https://github.com/lirantal/lockfile-lint).

Add a reusable GitHub workflow "tag & publish" for JS projects (#2)

When this new workflow can run it does:

  • (1) Create a new git tag if a new version is detected in package.json
  • (2-a) Create a new GitHub release linked to the newly created git tag
  • (2-b) Publish the add-on to npm using the newly created git tag

Note: the jobs 2-a and 2-b run in parallel.

It accepts 2 inputs from the caller workflow1:

  • nodejs_version (optional)
    The version of Node.js to use.
    If not specified, the version 12 will be used (which is still a LTS for the moment)

  • package_manager (optional)
    Which package manager to use between npm and yarn.
    If not specified, yarn will be used.

It accepts 1 secret from the caller workflow1:

  • npm_automation_token (required)
    An NPM automation token authorised to publish versions.

Currently implemented in the repositories

Footnotes

  1. GitHub terminology
    See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows 2 3

@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch from f47d3f9 to 8470112 Compare October 29, 2021 14:14
@MrChocolatine MrChocolatine marked this pull request as ready for review October 29, 2021 14:16
@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch 2 times, most recently from 160a864 to bca5f8f Compare October 29, 2021 14:18
@@ -0,0 +1,105 @@
name: CI
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if it is a reusable workflow, the file must be located in:

<my_repo>/.github/workflows/<my_workflow>.yml

Otherwise we get the error:
https://github.com/peopledoc/ember-feature-controls/actions/runs/1399317821

Copy link
Contributor Author

@MrChocolatine MrChocolatine Oct 29, 2021

Choose a reason for hiding this comment

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

Following this comment, declaring concurrency is not yet supported at the root of a called workflow file:

https://github.com/peopledoc/ember-feature-controls/actions/runs/1399155003

It must be declared in the caller workflow.

@MrChocolatine MrChocolatine requested a review from a team October 29, 2021 14:54
@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch from bca5f8f to 759853d Compare October 29, 2021 16:11
@MrChocolatine MrChocolatine changed the title create reusable workflow for Ember.js add-ons Add reusable GitHub workflow "lint & tests" for Ember.js add-ons Oct 29, 2021
@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch 3 times, most recently from e84b9cb to b0e1e31 Compare October 29, 2021 17:21
@MrChocolatine MrChocolatine marked this pull request as draft October 29, 2021 17:41
@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch 2 times, most recently from 6f9f0a4 to a2b7bd7 Compare October 29, 2021 18:30
Comment on lines 52 to 57
body: "\
Changelog: \
${{ github.server_url }}/${{ github.repository }}\
/compare/\
v${{ needs.create_git_tag.outputs.old_version }}...v${{ needs.create_git_tag.outputs.new_version }}\
"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why this syntax? => In order to split a long string over multiple lines, without getting a whitespace between each line.

See:
https://stackoverflow.com/questions/6268391/is-there-a-way-to-represent-a-long-string-that-doesnt-have-any-whitespace-on-mul

In comparison to:

body: >
  Changelog: 
  my_repo
  /compare/
  v1...v2

Which would result in the following string: (notice the whitespaces between each section)

Changelog: my_repo /compare/ v1...v2

# GitHub Actions documentation:
# https://docs.github.com/en/actions

name: Create new `git tag`, create new GitHub release and publish to NPM
Copy link
Contributor

@GreatWizard GreatWizard Nov 2, 2021

Choose a reason for hiding this comment

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

Should we rename it js-tag-release-publish?
If I'm correct we don't have any EmberJS related code in this workflow?

Copy link
Contributor Author

@MrChocolatine MrChocolatine Nov 2, 2021

Choose a reason for hiding this comment

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

Ah true true, good remark.

That would require an update to the CODEOWNERS file.

Following your suggestion, what about this @GreatWizard :

  • Move the workflow .github/workflows/emberjs-addons-ci.yml
    to .github/workflows/js/emberjs-addons-ci.yml

  • Move the workflow .github/workflows/emberjs-addons-tag-release-publish.yml
    to .github/workflows/js/tag-release-publish.yml

    ⬆️. Your suggestion

  • Update the CODEOWNERS to make the Tribe owner of the pattern:

# To match the directory `js` and all its subdirectories
/.github/workflows/js/                  @peopledoc/tribe-js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't put workflows into subdirectories è_é.

See commit b4c7f08 .

- name: Set up Node.js
uses: actions/setup-node@v2
with:
cache: yarn
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be possible to override this option.
Probabbly use npm by default and let the integration specify "yarn"

Copy link
Contributor Author

@MrChocolatine MrChocolatine Nov 2, 2021

Choose a reason for hiding this comment

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

We can indeed, many other things could be parametised but do we want it in this first version? As all our repo use yarn.

Copy link
Contributor

Choose a reason for hiding this comment

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

right , I'm fine with it tbh :) at least add it in inputs with yarn by default ? just to be future proof

registry-url: https://registry.npmjs.org

- name: Install Dependencies
run: yarn install --frozen-lockfile
Copy link
Contributor

Choose a reason for hiding this comment

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

this command should be yarn/npm agnostic too?
In addition, we don't even specify the package manager for the cache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, as decided together, it is a first version that only targets our public add-ons on npm, which all use yarn. I did not feel the need to make the workflows more complex than they really need 🤔 .

@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch 5 times, most recently from 4ac1b6f to c101c6c Compare November 2, 2021 13:31
@MrChocolatine MrChocolatine marked this pull request as draft November 2, 2021 13:32
@MrChocolatine MrChocolatine changed the title Add reusable GitHub workflow "lint & tests" for Ember.js add-ons Add reusable GitHub workflows "lint & tests" and "tag & publish" for JS projects Nov 2, 2021
@MrChocolatine MrChocolatine force-pushed the add-reusable-workflow-emberjs-addon branch from c101c6c to 4c25fc1 Compare November 2, 2021 13:41
@MrChocolatine MrChocolatine marked this pull request as ready for review November 2, 2021 13:44
@MrChocolatine MrChocolatine marked this pull request as draft November 2, 2021 13:46
@MrChocolatine MrChocolatine marked this pull request as ready for review November 2, 2021 14:16
@GreatWizard GreatWizard merged commit 6aa273b into main Nov 2, 2021
@GreatWizard GreatWizard deleted the add-reusable-workflow-emberjs-addon branch November 2, 2021 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ember.js Relates to Ember.js framework tribe-js
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants