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

dont try to push pod if its a canary release #123

Merged
merged 2 commits into from
Jan 19, 2023
Merged
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
36 changes: 25 additions & 11 deletions scripts/after-shipit-pod-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ const { execSync } = require('child_process');
class AfterShipItPodPush {
name = 'after-shipit-pod-push';

wasCanary = false;

apply(auto) {
auto.hooks.canary.tap(this.name, () => {
Copy link
Member

Choose a reason for hiding this comment

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

This looks good to me. Only thought is if it would make sense just to early return if we release is undefined and log? Just trying to think if there are any other use cases where afterShipIt would be invoked but not have an actual release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK theres only 3 flows, release, prerelease and canary? and the first two we do have tags, so if we get the canary hook called, i can skip even hitting the release API since i know it wont have a tag

Copy link
Contributor Author

@hborawski hborawski Jan 19, 2023

Choose a reason for hiding this comment

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

i updated it to log an error if a release isnt found, rather than exploding, since we should have a release in the other scenarios, if it failed creating the release, auto would die before this plugin runs

this.wasCanary = true
})
auto.hooks.afterShipIt.tapPromise(this.name, async ({ dryRun, newVersion }) => {
if (dryRun) {
auto.logger.log.info(`Dry run: would have pushed pod to trunk`);
auto.logger.log.info('Dry run: would have pushed pod to trunk');
} else if (this.wasCanary) {
auto.logger.log.info('[AfterShipItPodPush]: Canary not yet supported, skipping pod push.')
} else {
let found = false
let attempt = 0

while (!found && attempt < 10) {
const { data } = await auto.git.github.repos.listReleases({owner: auto.config.owner, repo: auto.config.repo})
const release = data.find(element => element.tag_name === newVersion)
const { data: releaseData } = await auto.git.github.repos.getRelease({owner: auto.config.owner, repo: auto.config.repo, release_id: release.id})
const zip = releaseData.assets.find(element => element.name === 'PlayerUI_Pod.zip' && element.state === 'uploaded')
if (release) {
const { data: releaseData } = await auto.git.github.repos.getRelease({owner: auto.config.owner, repo: auto.config.repo, release_id: release.id})
const zip = releaseData.assets.find(element => element.name === 'PlayerUI_Pod.zip' && element.state === 'uploaded')

found = !!zip
}

found = !!zip
if (!found) {
attempt++
await new Promise((resolve) => {
Expand All @@ -29,13 +39,17 @@ class AfterShipItPodPush {
}
}

auto.logger.log.info('Pushing Pod to trunk')
let process
try {
process = execSync('bundle exec pod trunk push --skip-tests ./bazel-bin/PlayerUI.podspec')
} catch(e) {
auto.logger.log.error('Pod push failed: ', process && process.stderr.toString(), e)
throw e
if (found) {
auto.logger.log.info('Pushing Pod to trunk')
let process
try {
process = execSync('bundle exec pod trunk push --skip-tests ./bazel-bin/PlayerUI.podspec')
} catch(e) {
auto.logger.log.error('Pod push failed: ', process && process.stderr.toString(), e)
throw e
}
} else {
auto.logger.log.error('[AfterShipItPodPush]: Release not found, skipping pod push')
}
}
});
Expand Down