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

CI - Make workflows sequential + concurrency mode + lint lockfile #163

Merged
merged 4 commits into from Oct 29, 2021

Conversation

MrChocolatine
Copy link
Member

@MrChocolatine MrChocolatine commented Oct 27, 2021

CI

Run workflow tag-release-publish only after lint & tests passed (#163)

Make the workflow tag-release-publish waits for the workflow CI to finish, so that they run sequentially (the same way jobs' steps are run sequentially).

Ensure only 1 workflow runs at a time (#163)

Surprisingly, while a new run of the workflow is triggered when pushing new changes, any previous workflow still running is not cancelled, resulting in a waste of resources.

We now use the concurrency setting to ensure that only a single workflow, using the same concurrency group, will run at a time.

Lint yarn.lock file to spot malicious attacks (#163)

@MrChocolatine MrChocolatine added the ci Continuous Integration label Oct 27, 2021

jobs:
create-git-tag:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
Copy link
Member Author

Choose a reason for hiding this comment

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

This if condition is needed because:

https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_run

workflow_run
(...)
A workflow run is triggered regardless of the result of the previous workflow.

branches:
- master
workflow_run:
workflows: CI
Copy link
Member Author

Choose a reason for hiding this comment

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

@MrChocolatine MrChocolatine marked this pull request as ready for review October 27, 2021 17:25
@MrChocolatine MrChocolatine requested a review from a team as a code owner October 27, 2021 17:25
@MrChocolatine MrChocolatine changed the title ci: run workflow only after lint & tests passed CI - Run workflow tag-release-publish only after lint & tests passed Oct 27, 2021
@MrChocolatine MrChocolatine force-pushed the ci-only-deploy-if-tests-passed branch 5 times, most recently from 48c4a66 to acbeff9 Compare October 28, 2021 15:06
Comment on lines +12 to +14
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently the workflows `CI` and `tag-release-publish` are executed in
parallel:

- Workflow `CI`
  https://github.com/peopledoc/ember-cli-embedded/runs/4020380098?check_suite_focus=true#step:1:1

- Workflow `tag-release-publish`
  https://github.com/peopledoc/ember-cli-embedded/runs/4020380101?check_suite_focus=true#step:1:1

By enabling the option `Show timestamps`, using the cog on the right, we
can see both started at the same time (+/- a few seconds of difference).

Which is wrong as we could potentially tag/release/publish while the
lint/tests failed. (this is unlikely to happen since the workflow `CI`
already runs for any pull request, but better safe than sorry right?)

---

This `if` condition is needed because:

https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_run

> `workflow_run`
> (...)
> A workflow run is triggered regardless of the result of the previous workflow.
@MrChocolatine MrChocolatine changed the title CI - Run workflow tag-release-publish only after lint & tests passed CI - Make workflows sequential + concurrency mode + lint lockfile Oct 28, 2021
As of now, `npx` in npm v6 does not prompt about the package about to
be used.

But things change with npm v7 where `npx` now prompts before installing
anything.

https://docs.npmjs.com/cli/v7/commands/npx

> To prevent security and user-experience problems from mistyping
> package names, `npx` prompts before installing anything. Suppress this
> prompt with the `-y` or `--yes` option.

However this flag `--yes` is not supported by npm v6 and would result in
an error if used. We need to set that flag through `npm_config_`:

https://docs.npmjs.com/cli/v6/using-npm/config

> Any environment variables that start with `npm_config_` will be
> interpreted as a configuration parameter. For example, putting
> `npm_config_foo=bar` in your environment will set the `foo`
> configuration parameter to `bar`. Any environment configurations that
> are not given a value will be given the value of true. Config values
> are case-insensitive, so `NPM_CONFIG_FOO=bar` will work the same.

See:
- https://dev.to/omrilotan/npx-breaking-on-ci-48ak
@MrChocolatine MrChocolatine merged commit c427c3e into master Oct 29, 2021
@MrChocolatine MrChocolatine deleted the ci-only-deploy-if-tests-passed branch October 29, 2021 12:20
@MrChocolatine MrChocolatine mentioned this pull request Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants