@ckeditor/ckeditor5-dev-ci 40.3.1 → 40.5.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
5
+ * For licensing, see LICENSE.md.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const circleUpdateAutoCancelBuilds = require( '../lib/circle-update-auto-cancel-builds' );
11
+
12
+ /**
13
+ * This script updates CircleCI settings to disable the "Auto-cancel redundant workflows" option.
14
+ *
15
+ * It's needed when triggering a release process via CI to avoid canceling the release workflow by pushing
16
+ * a new commit (the released one) that will trigger a new pipeline.
17
+ *
18
+ * In order to integrate the action in your pipeline, you need prepare a few environment variables:
19
+ *
20
+ * - CKE5_CIRCLE_TOKEN - an authorization token to talk to CircleCI REST API.
21
+ * - CKE5_GITHUB_ORGANIZATION - your GitHub organization.
22
+ * - CKE5_GITHUB_REPOSITORY - your GitHub repository.
23
+ *
24
+ * Example usage:
25
+ * CKE5_CIRCLE_TOKEN=... ckeditor5-dev-ci-circle-disable-auto-cancel-builds
26
+ */
27
+
28
+ const {
29
+ CKE5_CIRCLE_TOKEN,
30
+ CKE5_GITHUB_ORGANIZATION,
31
+ CKE5_GITHUB_REPOSITORY
32
+ } = process.env;
33
+
34
+ const options = {
35
+ circleToken: CKE5_CIRCLE_TOKEN,
36
+ githubOrganization: CKE5_GITHUB_ORGANIZATION,
37
+ githubRepository: CKE5_GITHUB_REPOSITORY,
38
+ newValue: false
39
+ };
40
+
41
+ circleUpdateAutoCancelBuilds( options )
42
+ .then( () => {
43
+ console.log( 'Auto-cancel redundant workflows is now disabled.' );
44
+ } )
45
+ .catch( err => {
46
+ console.error( err );
47
+
48
+ process.exit( 1 );
49
+ } );
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
5
+ * For licensing, see LICENSE.md.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const circleUpdateAutoCancelBuilds = require( '../lib/circle-update-auto-cancel-builds' );
11
+
12
+ /**
13
+ * This script updates CircleCI settings to enable the "Auto-cancel redundant workflows" option.
14
+ *
15
+ * It should be done only if a release workflow uses the `ckeditor5-dev-ci-circle-disable-auto-cancel-builds`
16
+ * script to disable the same option.
17
+ *
18
+ * In order to integrate the action in your pipeline, you need prepare a few environment variables:
19
+ *
20
+ * - CKE5_CIRCLE_TOKEN - an authorization token to talk to CircleCI REST API.
21
+ * - CKE5_GITHUB_ORGANIZATION - your GitHub organization.
22
+ * - CKE5_GITHUB_REPOSITORY - your GitHub repository.
23
+ *
24
+ * Example usage:
25
+ * CKE5_CIRCLE_TOKEN=... ckeditor5-dev-ci-circle-enable-auto-cancel-builds
26
+ */
27
+
28
+ const {
29
+ CKE5_CIRCLE_TOKEN,
30
+ CKE5_GITHUB_ORGANIZATION,
31
+ CKE5_GITHUB_REPOSITORY
32
+ } = process.env;
33
+
34
+ const options = {
35
+ circleToken: CKE5_CIRCLE_TOKEN,
36
+ githubOrganization: CKE5_GITHUB_ORGANIZATION,
37
+ githubRepository: CKE5_GITHUB_REPOSITORY,
38
+ newValue: true
39
+ };
40
+
41
+ circleUpdateAutoCancelBuilds( options )
42
+ .then( () => {
43
+ console.log( 'Auto-cancel redundant workflows is now enabled.' );
44
+ } )
45
+ .catch( err => {
46
+ console.error( err );
47
+
48
+ process.exit( 1 );
49
+ } );
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
5
+ * For licensing, see LICENSE.md.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const isJobTriggeredByMember = require( '../lib/is-job-triggered-by-member' );
11
+
12
+ /**
13
+ * This script checks if a user that approved an approval job could do that.
14
+ *
15
+ * In order to integrate the action in your pipeline, you need prepare a few environment variables:
16
+ *
17
+ * - CIRCLE_WORKFLOW_ID - provided by default by CircleCI and keeps a unique id of the CI build.
18
+ * - CKE5_CIRCLE_TOKEN - an authorization token to talk to CircleCI REST API.
19
+ * - CKE5_CIRCLE_APPROVAL_JOB_NAME - a job name to verify.
20
+ * - CKE5_GITHUB_TOKEN - a GitHub token used for authorization a request.
21
+ * - CKE5_GITHUB_TEAM_SLUG - a GitHub team slug that defines accounts that could approve the job.
22
+ * - CKE5_GITHUB_ORGANIZATION - your GitHub organization.
23
+ *
24
+ * Example usage:
25
+ * CKE5_CIRCLE_TOKEN=... ckeditor5-dev-ci-is-job-triggered-by-member
26
+ */
27
+
28
+ const {
29
+ CIRCLE_WORKFLOW_ID,
30
+ CKE5_CIRCLE_TOKEN,
31
+ CKE5_CIRCLE_APPROVAL_JOB_NAME,
32
+ CKE5_GITHUB_TOKEN,
33
+ CKE5_GITHUB_TEAM_SLUG,
34
+ CKE5_GITHUB_ORGANIZATION
35
+ } = process.env;
36
+
37
+ const options = {
38
+ circleToken: CKE5_CIRCLE_TOKEN,
39
+ circleWorkflowId: CIRCLE_WORKFLOW_ID,
40
+ circleApprovalJobName: CKE5_CIRCLE_APPROVAL_JOB_NAME,
41
+ githubOrganization: CKE5_GITHUB_ORGANIZATION,
42
+ githubTeamSlug: CKE5_GITHUB_TEAM_SLUG,
43
+ githubToken: CKE5_GITHUB_TOKEN
44
+ };
45
+
46
+ isJobTriggeredByMember( options )
47
+ .then( result => {
48
+ if ( !result ) {
49
+ console.log( `This account cannot approve the "${ options.circleApprovalJobName }" job. Aborting.` );
50
+ process.exit( 1 );
51
+ }
52
+
53
+ console.log( `The "${ options.circleApprovalJobName }" job was approved by a team member.` );
54
+ } )
55
+ .catch( err => {
56
+ console.error( err );
57
+
58
+ process.exit( 1 );
59
+ } );
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
5
+ * For licensing, see LICENSE.md.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const triggerCircleBuild = require( '../lib/trigger-circle-build' );
11
+
12
+ /**
13
+ * This script triggers a new CircleCI build.
14
+ *
15
+ * In order to integrate the action in your pipeline, you need prepare a few environment variables:
16
+ *
17
+ * - CIRCLE_BRANCH - provided by default by CircleCI and keeps the git branch of processed build.
18
+ * - CKE5_COMMIT_SHA1 - a full commit identifier of the processed the build.
19
+ * - CKE5_CIRCLE_TOKEN - an authorization token to talk to CircleCI REST API.
20
+ * - CKE5_GITHUB_REPOSITORY_SLUG - a repository slug (org/name) where a new build will be started.
21
+ * - CKE5_GITHUB_RELEASE_BRANCH - (optional) define a branch that leads the release process.
22
+ * - CKE5_GITHUB_TRIGGER_REPOSITORY_SLUG - (optional) a repository slug (org/name) that triggers a new build.
23
+ *
24
+ * Example usage:
25
+ * CKE5_CIRCLE_TOKEN=... ckeditor5-dev-ci-trigger-circle-build
26
+ */
27
+
28
+ const {
29
+ CKE5_COMMIT_SHA1,
30
+ CIRCLE_BRANCH,
31
+ CKE5_CIRCLE_TOKEN,
32
+ CKE5_GITHUB_RELEASE_BRANCH,
33
+ CKE5_GITHUB_REPOSITORY_SLUG,
34
+ CKE5_GITHUB_TRIGGER_REPOSITORY_SLUG
35
+ } = process.env;
36
+
37
+ const options = {
38
+ circleToken: CKE5_CIRCLE_TOKEN,
39
+ commit: CKE5_COMMIT_SHA1,
40
+ branch: CIRCLE_BRANCH,
41
+ releaseBranch: CKE5_GITHUB_RELEASE_BRANCH,
42
+ repositorySlug: CKE5_GITHUB_REPOSITORY_SLUG
43
+ };
44
+
45
+ if ( CKE5_GITHUB_TRIGGER_REPOSITORY_SLUG ) {
46
+ options.triggerRepositorySlug = CKE5_GITHUB_TRIGGER_REPOSITORY_SLUG;
47
+ }
48
+
49
+ triggerCircleBuild( options )
50
+ .then( () => {
51
+ console.log( 'CI triggered successfully.' );
52
+ } )
53
+ .catch( err => {
54
+ console.error( err );
55
+
56
+ process.exit( 1 );
57
+ } );
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const fetch = require( 'node-fetch' );
9
+
10
+ /**
11
+ * @param options
12
+ * @param {String} options.circleToken
13
+ * @param {String} options.githubOrganization
14
+ * @param {String} options.githubRepository
15
+ * @param {Boolean} options.newValue
16
+ * @return {Promise.<Boolean>}
17
+ */
18
+ module.exports = async function circleUpdateAutoCancelBuilds( options ) {
19
+ const {
20
+ circleToken,
21
+ githubOrganization,
22
+ githubRepository,
23
+ newValue
24
+ } = options;
25
+
26
+ const circleRequestOptions = {
27
+ method: 'patch',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ 'Circle-Token': circleToken
31
+ },
32
+ body: JSON.stringify( {
33
+ advanced: {
34
+ autocancel_builds: newValue
35
+ }
36
+ } )
37
+ };
38
+
39
+ const settingsUpdateUrl = `https://circleci.com/api/v2/project/github/${ githubOrganization }/${ githubRepository }/settings`;
40
+
41
+ return fetch( settingsUpdateUrl, circleRequestOptions )
42
+ .then( r => r.json() );
43
+ };
package/lib/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ module.exports = {
9
+ getJobApprover: require( './utils/get-job-approver' ),
10
+ members: require( './data/members.json' )
11
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const { Octokit } = require( '@octokit/rest' );
9
+ const getJobApprover = require( './utils/get-job-approver' );
10
+
11
+ /**
12
+ * @param options
13
+ * @param {String} options.circleToken
14
+ * @param {String} options.circleWorkflowId
15
+ * @param {String} options.circleApprovalJobName
16
+ * @param {String} options.githubOrganization
17
+ * @param {String} options.githubTeamSlug
18
+ * @param {String} options.githubToken
19
+ * @return {Promise.<Boolean>}
20
+ */
21
+ module.exports = async function isJobTriggeredByMember( options ) {
22
+ const {
23
+ circleToken,
24
+ circleWorkflowId,
25
+ circleApprovalJobName,
26
+ githubOrganization,
27
+ githubTeamSlug,
28
+ githubToken
29
+ } = options;
30
+
31
+ const login = await getJobApprover( circleToken, circleWorkflowId, circleApprovalJobName );
32
+ const octokit = new Octokit( { auth: githubToken } );
33
+ const { data } = await octokit.request( 'GET /orgs/{org}/teams/{team_slug}/members', {
34
+ org: githubOrganization,
35
+ team_slug: githubTeamSlug,
36
+ headers: {
37
+ 'X-GitHub-Api-Version': '2022-11-28'
38
+ }
39
+ } );
40
+
41
+ return data
42
+ .map( ( { login } ) => login )
43
+ .includes( login );
44
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ /* eslint-env node */
7
+
8
+ const fetch = require( 'node-fetch' );
9
+
10
+ /**
11
+ * @param options
12
+ * @param {String} options.circleToken
13
+ * @param {String} options.commit
14
+ * @param {String} options.branch
15
+ * @param {String} options.repositorySlug A repository slug (org/name) where a new build will be started.
16
+ * @param {String|null} [options.releaseBranch=null] Define a branch that leads the release process.
17
+ * @param {String|null} [options.triggerRepositorySlug=null] A repository slug (org/name) that triggers a new build.
18
+ * @return {Promise}
19
+ */
20
+ module.exports = async function triggerCircleBuild( options ) {
21
+ const {
22
+ circleToken,
23
+ commit,
24
+ branch,
25
+ repositorySlug,
26
+ releaseBranch = null,
27
+ triggerRepositorySlug = null
28
+ } = options;
29
+
30
+ const requestUrl = `https://circleci.com/api/v2/project/github/${ repositorySlug }/pipeline`;
31
+
32
+ const parameters = {
33
+ triggerCommitHash: commit
34
+ };
35
+
36
+ if ( releaseBranch ) {
37
+ parameters.isRelease = branch === releaseBranch;
38
+ }
39
+
40
+ if ( triggerRepositorySlug ) {
41
+ parameters.triggerRepositorySlug = triggerRepositorySlug;
42
+ }
43
+
44
+ const requestOptions = {
45
+ method: 'post',
46
+ headers: {
47
+ 'Content-Type': 'application/json',
48
+ 'Accept': 'application/json',
49
+ 'Circle-Token': circleToken
50
+ },
51
+ body: JSON.stringify( { branch, parameters } )
52
+ };
53
+
54
+ return fetch( requestUrl, requestOptions )
55
+ .then( res => res.json() )
56
+ .then( response => {
57
+ if ( response.error_message ) {
58
+ throw new Error( `CI trigger failed: "${ response.error_message }".` );
59
+ }
60
+ } );
61
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const fetch = require( 'node-fetch' );
9
+
10
+ /**
11
+ * Returns a promise that resolves to GitHub name of a developer who approved the `jobName` job.
12
+ *
13
+ * @param {String} circleCiToken
14
+ * @param {String} workflowId
15
+ * @param {String} jobName
16
+ * @returns {Promise.<String>}
17
+ */
18
+ module.exports = async function getJobApprover( circleCiToken, workflowId, jobName ) {
19
+ const circleRequestOptions = {
20
+ method: 'get',
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ 'Accept': 'application/json',
24
+ 'Circle-Token': circleCiToken
25
+ }
26
+ };
27
+
28
+ // Find an identifier of a developer who approved an approval job.
29
+ const workflowJobsUrl = `https://circleci.com/api/v2/workflow/${ workflowId }/job`;
30
+ const workflowJobs = await fetch( workflowJobsUrl, circleRequestOptions ).then( r => r.json() );
31
+ const { approved_by: approvedBy } = workflowJobs.items.find( job => job.name === jobName );
32
+
33
+ // Find a username based on the identifier.
34
+ const userDetailsUrl = `https://circleci.com/api/v2/user/${ approvedBy }`;
35
+ const { login } = await fetch( userDetailsUrl, circleRequestOptions ).then( r => r.json() );
36
+
37
+ return login;
38
+ };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-dev-ci",
3
- "version": "40.3.1",
3
+ "version": "40.5.0-alpha.0",
4
4
  "description": "Utils used on various Continuous Integration services.",
5
5
  "keywords": [],
6
+ "main": "lib/index.js",
6
7
  "dependencies": {
7
8
  "minimist": "^1.2.5",
8
9
  "node-fetch": "^2.6.7",
@@ -21,7 +22,11 @@
21
22
  "ckeditor5-dev-ci-notify-circle-status": "bin/notify-circle-status.js",
22
23
  "ckeditor5-dev-ci-circle-workflow-notifier": "bin/circle-workflow-notifier.js",
23
24
  "ckeditor5-dev-ci-allocate-swap-memory": "bin/allocate-swap-memory.sh",
24
- "ckeditor5-dev-ci-install-latest-chrome": "bin/install-latest-chrome.sh"
25
+ "ckeditor5-dev-ci-install-latest-chrome": "bin/install-latest-chrome.sh",
26
+ "ckeditor5-dev-ci-is-job-triggered-by-member": "bin/is-job-triggered-by-member.js",
27
+ "ckeditor5-dev-ci-trigger-circle-build": "bin/trigger-circle-build.js",
28
+ "ckeditor5-dev-ci-circle-disable-auto-cancel-builds": "bin/circle-disable-auto-cancel-builds.js",
29
+ "ckeditor5-dev-ci-circle-enable-auto-cancel-builds": "bin/circle-enable-auto-cancel-builds.js"
25
30
  },
26
31
  "author": "CKSource (http://cksource.com/)",
27
32
  "license": "GPL-2.0-or-later",