Skip to content

Commit

Permalink
rollback github
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Nov 28, 2023
1 parent 4c16511 commit ddb8425
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
11 changes: 11 additions & 0 deletions codebuild_specs/release_workflows/github_rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 0.2
env:
shell: bash
phases:
build:
commands:
- source ./shared-scripts.sh && _githubRollback

artifacts:
files:
- 'shared-scripts.sh'
6 changes: 6 additions & 0 deletions codebuild_specs/release_workflows/rollback_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ batch:
buildspec: codebuild_specs/validate_rollback_target_version.yml
depend-on:
- install_dependencies
- identifier: github_rollback
buildspec: codebuild_specs/release_workflows/github_rollback.yml
env:
compute-type: BUILD_GENERAL1_LARGE
depend-on:
- validate_rollback_target_version
# - identifier: verify_yarn_lock
# buildspec: codebuild_specs/verify_yarn_lock.yml
# depend-on:
Expand Down
2 changes: 1 addition & 1 deletion scripts/github-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
/**
* Some constants and utils shared by github-prerelease and github-release
*/
const owner = 'aws-amplify';
const owner = process.env.GITHUB_REPO_OWNER ?? 'aws-amplify';
const repo = 'amplify-cli';
const apiTemplate = (subdomain: string) => `${subdomain}.github.com/repos/${owner}/${repo}/releases`;
const API_URL = apiTemplate('api');
Expand Down
26 changes: 26 additions & 0 deletions scripts/github-rollback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { releasesRequest, semverToGithubTag } from './github-common';
import { join } from 'path';

/**
* This function expects a 'version' to already exist.
* The release with proved version is marked as latest.
*/
const markReleaseAsLatest = async (version: string) => {
const { id: releaseId } = await releasesRequest(join('tags', semverToGithubTag(version)));
const releaseIdStr = (releaseId as number).toString();
console.log('Publishing release');
await releasesRequest(releaseIdStr, {
method: 'PATCH',
body: JSON.stringify({
prerelease: false,
make_latest: 'true',
}),
});
};

const main = async () => {
const version = process.argv[2].trim();
await markReleaseAsLatest(version);
};

main();
9 changes: 9 additions & 0 deletions shared-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ function _githubRelease {
version=$(cat .amplify-pkg-version)
yarn ts-node scripts/github-release.ts $version $commit
}
function _githubRollback {
loadCache repo $CODEBUILD_SRC_DIR
echo Rollback Amplify CLI GitHub release
if [ -z "$ROLLBACK_TARGET_VERSION" ]; then
echo "Rollback target version is missing. Make sure CodeBuild workflow was started with ROLLBACK_TARGET_VERSION environment variable"
exit 1
fi
yarn ts-node scripts/github-rollback.ts $ROLLBACK_TARGET_VERSION
}
function _amplifyGeneralConfigTests {
_loadE2ECache
_install_packaged_cli_linux
Expand Down

0 comments on commit ddb8425

Please sign in to comment.