Skip to content

Commit

Permalink
Allow envBranch to be passed in on CI (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
aswamy authored Jul 2, 2024
1 parent e432533 commit 710625c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-points-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

[Bug fix] Allow env-branch to be passed when running `h2 deploy` in CI
30 changes: 27 additions & 3 deletions packages/cli/src/commands/hydrogen/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('deploy', () => {
expect(vi.mocked(renderSuccess)).toHaveBeenCalled();
});

it('calls createDeploy against a environment selected by env', async () => {
it('calls createDeploy against an environment selected by env', async () => {
vi.mocked(getOxygenDeploymentData).mockResolvedValue({
oxygenDeploymentToken: 'some-encoded-token',
environments: [
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('deploy', () => {
expect(vi.mocked(renderSuccess)).toHaveBeenCalled;
});

it('calls createDeploy against a environment selected by envBranch', async () => {
it('calls createDeploy against an environment selected by envBranch', async () => {
vi.mocked(getOxygenDeploymentData).mockResolvedValue({
oxygenDeploymentToken: 'some-encoded-token',
environments: [
Expand Down Expand Up @@ -302,6 +302,30 @@ describe('deploy', () => {
expect(vi.mocked(renderSuccess)).toHaveBeenCalled;
});

it('calls createDeploy against an envBranch in CI', async () => {
vi.mocked(ciPlatform).mockReturnValue({
isCI: true,
name: 'github',
metadata: {},
});

await runDeploy({
...deployParams,
token: 'some-token',
envBranch: 'stage-1',
});

expect(vi.mocked(createDeploy)).toHaveBeenCalledWith({
config: {
...expectedConfig,
environmentTag: 'stage-1',
},
hooks: expectedHooks,
logger: deploymentLogger,
});
expect(vi.mocked(renderSuccess)).toHaveBeenCalled;
});

it("errors when the env provided doesn't match any environment", async () => {
await expect(
runDeploy({
Expand All @@ -311,7 +335,7 @@ describe('deploy', () => {
).rejects.toThrowError('Environment not found');
});

it("errors when the env provided doesn't match any environment", async () => {
it("errors when the envBranch provided doesn't match any environment", async () => {
await expect(
runDeploy({
...deployParams,
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/hydrogen/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ export async function runDeploy(
);
}

if (isCI && envBranch) {
userProvidedEnvironmentTag = envBranch;
}

if (!isCI) {
deploymentData = await getOxygenDeploymentData({
root,
Expand Down

0 comments on commit 710625c

Please sign in to comment.