Skip to content

Commit

Permalink
wait rollout by plan
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowDashy committed Jan 15, 2025
1 parent 54248f0 commit c479bba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,11 @@ jobs:
project: ${{ env.BYTEBASE_PROJECT }}
release: ${{ steps.create_release.outputs.release }}
targets: ${{ env.BYTEBASE_TARGETS }}
- name: Create rollout
id: create_rollout
uses: bytebase/actions-create-rollout@main
with:
url: ${{ env.BYTEBASE_URL }}
token: ${{ steps.login.outputs.token }}
project: ${{ env.BYTEBASE_PROJECT }}
plan: ${{ steps.create_plan.outputs.plan }}
- name: Wait rollout to finish
id: wait_rollout
uses: bytebase/actions-wait-rollout@main
with:
url: ${{ env.BYTEBASE_URL }}
token: ${{ steps.login.outputs.token }}
rollout: ${{ steps.create_rollout.outputs.rollout }}
plan: ${{ steps.create_plan.outputs.plan }}
```
5 changes: 3 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ inputs:
token:
description: The Bytebase access token.
required: true
rollout:
plan:
description:
'The rollout to wait. Format: projects/{project}/rollouts/{rollout}'
'The plan to create the rollout from. Format:
projects/{project}/plans/{plan}'
required: true
target-stage:
description: >
Expand Down
16 changes: 6 additions & 10 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export async function run(): Promise<void> {
try {
const url = core.getInput('url', { required: true })
const token = core.getInput('token', { required: true })
const rolloutName = core.getInput('rollout', { required: true })
const planName = core.getInput('plan', { required: true })
const targetStage = core.getInput('target-stage')

const m = rolloutName.match(/(?<project>projects\/.*)\/rollouts\/.*/)
const m = planName.match(/(?<project>projects\/.*)\/plans\/.*/)
if (!m || !m.groups || !m.groups['project']) {
throw new Error(`failed to extract project from rollout ${rolloutName}`)
throw new Error(`failed to extract project from plan ${planName}`)
}
const project = m.groups['project']

Expand All @@ -27,13 +27,6 @@ export async function run(): Promise<void> {
})
}

const rollout = await getRollout(c, rolloutName)
const planName = rollout.plan as string
if (!planName) {
core.debug(`rollout: ${JSON.stringify(rollout)}`)
throw new Error(`failed to get rollout.plan`)
}

// Preview the rollout.
// The rollout may have no stages. We need to create stages as we are moving through the pipeline.
const rolloutPreview = await createRollout(
Expand All @@ -45,7 +38,10 @@ export async function run(): Promise<void> {
)
rolloutPreview.plan = planName

await waitRollout(c, project, rolloutPreview, rolloutName, targetStage)
// Create the rollout without any stage to obtain the rollout resource name.
const rollout = await createRollout(c, project, planName, false, '')

await waitRollout(c, project, rolloutPreview, rollout.name, targetStage)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down

0 comments on commit c479bba

Please sign in to comment.