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

Introduce npmCheckDay parameter to update-deps workflow #28

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.16.1
v14
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ Since this workflow uses labels to mark stale issues/PRs, labels should be alrea
* `resolution:expired` - label added to stale issues which got closed due to inactivity.
* `pr:frozen ❄` - label added to stale PRs which got closed due to inactivity.

### update-deps
### update-deps-semversion

Workflow responsible for updating NPM dependencies. It is run on 1st and 15th day of each month (at 05:00 UTC) and creates two PRs - one for dev dependencies and one for production ones (if there are any outdated dependencies). It checks `package.json` file in the repository root and uses `npm-check` to update all dev/prod dependencies (which means `package.json` versioning is not respected). It is a cron job task so will be triggered only on main repository branch. See `workflows/update-deps.yml` file.
Workflow responsible for updating NPM dependencies. It is run on 1st and 15th day of each month (at 05:00 UTC) and creates two PRs - one for dev dependencies and one for production ones (if there are any outdated dependencies). It checks `package.json` file in the repository root. Depends on provided config, it will use `npm-check` (`semversion` compatibility mode) or `npm_update` (bump version to newest available) to update all dev/prod dependencies. It is a cron job task so will be triggered only on main repository branch. See `workflows/update-deps-semversion.yml` file.

### update-deps-to-newest

Workflow responsible for running `update-deps-semversion` workflow, but with config that disables semversion compatibility. It is scheduled to run once a month. See `workflows/update-deps-to-newest.yml` file.

#### Required secrets

Expand All @@ -116,18 +120,31 @@ Workflow responsible for updating NPM dependencies. It is run on 1st and 15th da

### Running tests

To run tests, create `.env` file with the following variables:
To run tests, in the `ckeditor4-workflows-common` repo create an `.env` file with the following variables:

* `AUTH_KEY` - GitHub key with permissions to commit files, read and run workflows / actions.
* `AUTH_KEY` - GitHub key with permissions to commit files, read and run workflows / actions. To get a token follow [Creating a personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) tutorial.
* `OWNER` - Owner of tests repo, e.g. `ckeditor`.
* `REPO` - Tests repo name, e.g. `workflow-tests`. It should be an empty repository with `master` branch and `README.md` file only.
* `REPO` - Tests repo name, e.g. `workflow-tests`. It should be an empty repository with `master` branch and `README.md` file only. Remember it also requires setting your GH Secrets on repo level (the ones inherited from organization level probably won't work). For now to run all workflows you need 3 secrets:
* `GH_WORKFLOWS_TOKEN` (same as `AUTH_KEY` variable);
* `GH_BOT_EMAIL` (most likely you );
* `GH_BOT_USERNAME`.
Comment on lines +128 to +130
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it depends - if you create a repo in ckeditor org (which below sample env file contents suggests), our standard GH_BOT_* values should work here? Or not 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIR they didn't work and you need to provide your own... ;( They seem to be active if you take a look into repo settings, but they are not working with the script... If you override them with the new one - it works fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ The last one seems to be most promising IMHO, but it's still a bit complex. Maybe sticking to simple solution which we have now would be enough 🤔

TBH, I think the solution with a separate workflow that dispatches another workflow seems to be most valid for me. We can freely manipulate the schedule with cron. If we decide that the current approach (once a month) is no longer valid we'll be forced to adjust a lot of code. We do the effort now and have a more elastic solution.


Then run:
So the file should look like this:

```
AUTH_KEY="ghp_heregoesquitealonghash"
OWNER="ckeditor"
REPO="workflow-tests-PR-100"
```

Then (still being in `ckeditor4-workflows-common` repo) run:

```
npm test
```

Remember to use appropriate Node.js version (v14). After tests are finished, you need to manually check in testing repo if everything was done as it should be (tests only check if workflows were executed).

### Adding tests

Tests case for new workflows should be added in `tests/fixtures` directory - for example `new-workflow.yml` should be covered with tests from `tests/fixtures/new-workflow.js`. The test file should export array of tests cases (see example below).
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"homepage": "https://github.com/ckeditor/ckeditor4-workflows-common#readme",
"dependencies": {
"@octokit/request": "^5.4.14",
"dotenv": "^8.2.0",
"chalk": "^4.1.0"
"chalk": "^4.1.1",
"dotenv": "^8.2.0"
}
}
18 changes: 18 additions & 0 deletions tests/assets/deps-package-outdated-fixed-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "fixtures",
"version": "1.0.0",
"description": "",
"main": "setup-workflows.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"core-js": "2.0.0",
"eslint": "5.0.0"
},
"dependencies": {
"chalk": "3.0.0"
}
}
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/assets/deps-package-up-to-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "fixtures",
"version": "1.0.0",
"description": "",
"main": "setup-workflows.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"core-js": "^2.6.12",
"eslint": "^7.27.0"
},
"dependencies": {
"chalk": "^4.1.1"
}
}
1 change: 1 addition & 0 deletions tests/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const dotenv = require( 'dotenv' );
const chalk = require( 'chalk' );

function config() {
dotenv.config();
Expand Down
8 changes: 2 additions & 6 deletions tests/fixtures/setup-workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module.exports = [ {
workflow: 'setup-workflows.yml',
branch: 'master',
config: {
'setupWorkflows': {
'pushAsPullRequest': 'false'
}
'pushAsPullRequest': 'false'
}
}, {
name: 'setup-workflows direct push (no config)',
Expand All @@ -16,9 +14,7 @@ module.exports = [ {
workflow: 'setup-workflows.yml',
branch: 'master',
config: {
'setupWorkflows': {
'pushAsPullRequest': 'true'
}
'pushAsPullRequest': 'true'
}
}
];
58 changes: 58 additions & 0 deletions tests/fixtures/update-deps-semversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let date = new Date();
let testNpmCheck = true;
let npmCheckDay = testNpmCheck ? date.getDate() : date.getDate() + 1;

module.exports = [
{
name: 'update-deps branch without package.json file',
workflow: 'update-deps-semversion.yml',
branch: 'master',
config: {
'targetBranch': 'master'
}
}, {
name: 'update-deps on up-to-date branch',
workflow: 'update-deps-semversion.yml',
branch: 'master',
config: {
'targetBranch': 'master'
},
fileList: [ {
src: 'deps-package-up-to-date.json',
dest: 'package.json'
} ]
}, {
name: 'update-deps PR',
workflow: 'update-deps-semversion.yml',
branch: 'master',
config: {
'targetBranch': 'master'
},
fileList: [ {
src: 'deps-package-outdated.json',
dest: 'package.json'
} ]
}, {
name: 'update-deps with npm-check on custom day of month',
workflow: 'update-deps-semversion.yml',
branch: 'master',
config: {
'npmCheckDay': npmCheckDay
},
fileList: [ {
src: 'deps-package-outdated.json',
dest: 'package.json'
} ]
}, {
name: 'update-deps on non-existing branch',
workflow: 'update-deps-semversion.yml',
branch: 'master',
config: {
'targetBranch': 'main'
},
fileList: [ {
src: 'deps-package-outdated.json',
dest: 'package.json'
} ]
}
];
37 changes: 37 additions & 0 deletions tests/fixtures/update-deps-to-newest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = [
{
name: 'update-deps with empty init cfg',
workflow: 'update-deps-to-newest.yml',
branch: 'master',
config: {},
fileList: [ {
src: 'deps-package-outdated-fixed-version.json',
dest: 'package.json'
} ]
},
{
name: 'update-deps with targetBranch in cfg',
workflow: 'update-deps-to-newest.yml',
branch: 'master',
config: {
targetBranch: 'master'
},
fileList: [ {
src: 'deps-package-outdated-fixed-version.json',
dest: 'package.json'
} ]
},
{
name: 'update-deps with bump on false in cfg',
workflow: 'update-deps-to-newest.yml',
branch: 'master',
config: {
targetBranch: 'master',
bump: 'false'
},
fileList: [ {
src: 'deps-package-outdated-fixed-version.json',
dest: 'package.json'
} ]
}
];
14 changes: 0 additions & 14 deletions tests/fixtures/update-deps.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/helpers/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function runTest( testCase ) {
console.log( `Status: ${ chalk.yellow( workflowObject.status ) }. Result: ${ chalk.yellow( workflowObject.conclusion ) }. Next check in ${ waitingTime }ms` );
} );

console.log( chalk.green( result.name + 'run is finished!' ) + ' Result: ' + chalk.yellow( result.conclusion ) );
console.log( chalk.green( '"' + result.name + '" run is finished!' ) + ' Result: ' + chalk.yellow( result.conclusion ) );
console.log( `Details: https://github.com/${ process.env.OWNER }/${ process.env.REPO }/actions/runs/${ workflow.id }` );
}

Expand Down
31 changes: 25 additions & 6 deletions workflows/update-deps.yml → workflows/update-deps-semversion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update NPM dependencies
name: Update NPM dependencies(semversion)

on:
schedule:
Expand Down Expand Up @@ -59,20 +59,39 @@ jobs:
fi
echo "BRANCH_TARGET=$BRANCH_TARGET" >> $GITHUB_ENV

SHOULD_BUMP=$(echo '${{ env.CONFIG }}' | jq -r ".bump")
if [[ "$SHOULD_BUMP" == "true" ]]; then
echo "DEPS_BUMP_METHOD=npm-check" >> $GITHUB_ENV
else
echo "DEPS_BUMP_METHOD=npm_update" >> $GITHUB_ENV
fi

- name: Check if update branch already exists
run: |
echo "BRANCH_UPDATE=deps-update_${{ env.BRANCH_TARGET }}_${{ matrix.deps }}" >> $GITHUB_ENV
echo "BRANCH_UPDATE=deps-${{ env.DEPS_BUMP_METHOD}}_${{ env.BRANCH_TARGET }}_${{ matrix.deps }}" >> $GITHUB_ENV
if [[ $(git ls-remote --heads | grep deps-update_${{ env.BRANCH_TARGET }}_${{ matrix.deps }} | wc -c) -ne 0 ]]; then
echo "BRANCH_UPDATE=0" >> $GITHUB_ENV
fi

- name: Update NPM dependencies
if: env.BRANCH_UPDATE != 0
run: |
npm i
npm install -g npm-check
git checkout -b ${{ env.BRANCH_UPDATE }}
npm-check -y --${{ matrix.deps }}
if [[ ! -f "./package.json" ]]; then
echo "'package.json' file not found, with nothing to update the workflow ends here."
exit 0
fi

if [[ "${{ env.DEPS_BUMP_METHOD }}" == "npm_update" ]]; then
echo "Just npm update today!"
git checkout -b ${{ env.BRANCH_UPDATE }}
npm update
else
echo "Running npm-check!"
npm i
npm install -g npm-check
git checkout -b ${{ env.BRANCH_UPDATE }}
npm-check -y --${{ matrix.deps }}
fi

- name: Add changes
if: env.BRANCH_UPDATE != 0
Expand Down
40 changes: 40 additions & 0 deletions workflows/update-deps-to-newest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Update NPM dependencies(to newest)
on:
schedule:
- cron: "0 0 1 * *"
workflow_dispatch:
inputs:
config:
description: 'Config'
required: false
default: ''

jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Read config
run: |
CONFIG='{}'
if [[ ! -z '${{ github.event.inputs.config }}' ]]; then
CONFIG='${{ github.event.inputs.config }}'
elif [[ -f "./.github/workflows-config.json" ]]; then
CONFIG=$( jq -c .updateDeps './.github/workflows-config.json' )
fi
echo "Workflow config: $CONFIG"
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
- name: Merge configs
run: |
CONFIG=$(echo '${{ env.CONFIG }}' | jq -c '. += {"bump": "true"}')
# echo "${CONFIG}"
INPUT_1='{ "config": "'
INPUT_2=$(echo "${CONFIG//\"/\\\"}")
INPUT_3='"}'
INPUT_ALL="${INPUT_1} ${INPUT_2} ${INPUT_3}"
echo "INPUT_ALL=$INPUT_ALL" >> $GITHUB_ENV
- name: Invoke workflow with inputs
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Update NPM dependencies(semversion)
token: ${{ secrets.GH_WORKFLOWS_TOKEN }}
inputs: ${{ env.INPUT_ALL }}