Skip to content

Commit 72e714d

Browse files
author
Dane Pilcher
authored
ci: add deprecate workflow (#846)
1 parent 0ffe64f commit 72e714d

17 files changed

+536
-4
lines changed

.codebuild/deprecate.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 0.2
2+
env:
3+
shell: bash
4+
git-credential-helper: yes
5+
phases:
6+
build:
7+
commands:
8+
- source ./shared-scripts.sh && _deprecate

.codebuild/deprecate_workflow.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 0.2
2+
env:
3+
shell: bash
4+
compute-type: BUILD_GENERAL1_SMALL
5+
6+
batch:
7+
fast-fail: false
8+
build-graph:
9+
- identifier: install_linux
10+
buildspec: .codebuild/install_linux.yml
11+
- identifier: deprecate
12+
buildspec: .codebuild/deprecate.yml
13+
depend-on:
14+
- install_linux

.codebuild/install_linux.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 0.2
2+
env:
3+
shell: bash
4+
phases:
5+
build:
6+
commands:
7+
- source ./shared-scripts.sh && _installLinux
8+
artifacts:
9+
files:
10+
- 'shared-scripts.sh'

.codebuild/scripts/local_publish_helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
custom_registry_url=http://localhost:4873
4-
default_verdaccio_package=verdaccio@4.5.1
4+
55

66
function startLocalRegistry {
77
# Start local registry

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ package-lock.json
2929
.idea
3030
scripts/.env
3131
.codebuild/debug_workflow.yml
32+
.npmrc
33+
verdaccio-logs.txt
34+
scripts/components/private_packages.ts

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
**/package-lock.json
66
**/.eslintrc.js
77
**/tsconfig.json
8-
packages/*/CHANGELOG.md
8+
packages/*/CHANGELOG.md
9+
scripts/components/private_packages.ts

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"lint-fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
1111
"clean": "lerna run clean && lerna exec yarn rimraf tsconfig.tsbuildinfo && lerna clean --yes && yarn rimraf node_modules",
1212
"build": "lerna run build",
13-
"production-build": "yarn --ignore-engines --frozen-lockfile && lerna run build --concurrency 3 --stream",
13+
"production-install": "yarn --ignore-engines --frozen-lockfile",
14+
"production-build": "yarn production-install && lerna run build --concurrency 3 --stream",
1415
"publish:main": "lerna publish --canary --exact --force-publish --preid=dev --dist-tag=dev --include-merged-tags --conventional-prerelease --no-verify-access --yes",
1516
"publish:release": "lerna publish --exact --conventional-commits --message 'chore(release): Publish [ci skip]' --no-verify-access --yes",
1617
"publish:tag": "lerna publish --exact --dist-tag=$NPM_TAG --preid=$NPM_TAG --conventional-commits --conventional-prerelease --message 'chore(release): Publish tagged release $NPM_TAG [ci skip]' --no-verify-access --yes",
@@ -35,6 +36,7 @@
3536
"verify-api-extract": "yarn extract-api && ./scripts/verify-extract-api.sh",
3637
"trigger-release": "source ./scripts/cloud-release.sh && triggerRelease",
3738
"trigger-tag-release": "source ./scripts/cloud-release.sh && triggerTagRelease",
39+
"trigger-deprecate-release": "source ./scripts/cloud-release.sh && deprecateRelease",
3840
"view-test-artifact": "./scripts/view-test-artifacts.sh",
3941
"cleanup-stale-resources": "source ./scripts/cloud-utils.sh && cleanupStaleResources",
4042
"cloud-e2e": "source scripts/cloud-utils.sh && cloudE2E",
@@ -44,7 +46,9 @@
4446
"cloud-e2e-debug": "source scripts/cloud-utils.sh && cloudE2EDebug",
4547
"authenticate-e2e-profile": "source scripts/cloud-utils.sh && authenticateWithE2EProfile",
4648
"extract-dependency-licenses": "./scripts/extract-dependency-licenses.sh",
47-
"verify-dependency-licenses-extract": "yarn extract-dependency-licenses && ./scripts/verify-dependency-licenses.sh"
49+
"verify-dependency-licenses-extract": "yarn extract-dependency-licenses && ./scripts/verify-dependency-licenses.sh",
50+
"deprecate": "ts-node scripts/deprecate_release.ts",
51+
"postinstall": "./scripts/postinstall.sh"
4852
},
4953
"bugs": {
5054
"url": "https://github.com/aws-amplify/amplify-codegen/issues"

scripts/cloud-release.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source ./scripts/cloud-utils.sh
33
export RELEASE_ROLE_NAME=CodebuildDeveloper
44
export RELEASE_PROFILE_NAME=AmplifyAPIPluginRelease
55
export RELEASE_PROJECT_NAME=amplify-codegen-release-workflow
6+
export DEPRECATE_PROJECT_NAME=amplify-codegen-deprecate-workflow
67

78
function triggerRelease {
89
triggerProjectBatch $RELEASE_ACCOUNT_PROD $RELEASE_ROLE_NAME "${RELEASE_PROFILE_NAME}Prod" $RELEASE_PROJECT_NAME "release"
@@ -20,3 +21,13 @@ function triggerTagRelease {
2021
fi
2122
triggerProjectBatch $RELEASE_ACCOUNT_PROD $RELEASE_ROLE_NAME "${RELEASE_PROFILE_NAME}Prod" $RELEASE_PROJECT_NAME $branch_name
2223
}
24+
25+
function deprecateRelease {
26+
DEPRECATION_MESSAGE=$1
27+
SEARCH_FOR_RELEASE_STARTING_FROM=$2
28+
USE_NPM_REGISTRY=$3
29+
triggerProjectBatchWithEnvOverrides $RELEASE_ACCOUNT_PROD $RELEASE_ROLE_NAME "${RELEASE_PROFILE_NAME}Prod" $DEPRECATE_PROJECT_NAME "release" \
30+
name=DEPRECATION_MESSAGE,value=\""$DEPRECATION_MESSAGE"\",type=PLAINTEXT \
31+
name=SEARCH_FOR_RELEASE_STARTING_FROM,value=$SEARCH_FOR_RELEASE_STARTING_FROM,type=PLAINTEXT \
32+
name=USE_NPM_REGISTRY,value=$USE_NPM_REGISTRY,type=PLAINTEXT
33+
}

scripts/cloud-utils.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ function triggerProjectBatch {
3434
echo "https://$REGION.console.aws.amazon.com/codesuite/codebuild/$account_number/projects/$project_name/batch/$RESULT?region=$REGION"
3535
}
3636

37+
function triggerProjectBatchWithEnvOverrides {
38+
account_number=$1
39+
role_name=$2
40+
profile_name=$3
41+
project_name=$4
42+
target_branch=$5
43+
shift 5
44+
authenticate $account_number $role_name $profile_name
45+
echo AWS Account: $account_number
46+
echo Project: $project_name
47+
echo Target Branch: $target_branch
48+
RESULT=$(aws codebuild start-build-batch --region=$REGION --profile="${profile_name}" --project-name $project_name --source-version=$target_branch \
49+
--environment-variables-override name=BRANCH_NAME,value=$target_branch,type=PLAINTEXT "$@" \
50+
--query 'buildBatch.id' --output text)
51+
echo "https://$REGION.console.aws.amazon.com/codesuite/codebuild/$account_number/projects/$project_name/batch/$RESULT?region=$REGION"
52+
}
53+
3754
function triggerProject {
3855
account_number=$1
3956
role_name=$2

scripts/components/dist_tag_mover.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { EOL } from 'os';
2+
import { NpmClient } from './npm_client.js';
3+
import { releaseTagToNameAndVersion } from './release_tag_to_name_and_version';
4+
5+
type DistTagMoveAction = {
6+
/**
7+
* An NPM dist-tag
8+
*/
9+
distTag: string;
10+
/**
11+
* This is a string of the form <packageName>@<version>
12+
*/
13+
releaseTag: string;
14+
};
15+
16+
/**
17+
* Handles moving npm dist-tags from one package version to another
18+
*/
19+
export class DistTagMover {
20+
/**
21+
* Initialize with an npmClient
22+
*/
23+
constructor(private readonly npmClient: NpmClient) {}
24+
25+
/**
26+
* Given a list of sourceReleaseTags and destReleaseTags,
27+
* any npm dist-tags that are pointing to a sourceReleaseTag will be moved to point to the corresponding destReleaseTag
28+
*/
29+
moveDistTags = async (sourceReleaseTags: string[], destReleaseTags: string[]) => {
30+
const moveActions: DistTagMoveAction[] = [];
31+
32+
for (const sourceReleaseTag of sourceReleaseTags) {
33+
const { packageName, version: sourceVersion } = releaseTagToNameAndVersion(sourceReleaseTag);
34+
35+
const { 'dist-tags': distTags } = await this.npmClient.getPackageInfo(sourceReleaseTag);
36+
37+
Object.entries(distTags).forEach(([tagName, versionAtTag]) => {
38+
if (versionAtTag !== sourceVersion) {
39+
return;
40+
}
41+
const destReleaseTag = destReleaseTags.find(releaseTag => releaseTag.includes(packageName));
42+
if (!destReleaseTag) {
43+
console.warn(`No corresponding destination release tag found for ${sourceReleaseTag}. latest tag not moved.`);
44+
} else {
45+
moveActions.push({
46+
releaseTag: destReleaseTag,
47+
distTag: tagName,
48+
});
49+
}
50+
});
51+
}
52+
53+
for (const { distTag, releaseTag } of moveActions) {
54+
console.log(`Moving dist tag "${distTag}" to release tag ${releaseTag}`);
55+
await this.npmClient.setDistTag(releaseTag, distTag);
56+
console.log(`Done!${EOL}`);
57+
}
58+
};
59+
}

0 commit comments

Comments
 (0)