Skip to content

Commit

Permalink
Merge pull request #14 from vtex/extend/conflict-resolver
Browse files Browse the repository at this point in the history
Extend conflict resolver to handle all pages-graphql files(on promote)
  • Loading branch information
vitorflg authored Oct 24, 2024
2 parents 97354bb + 1ef23e6 commit a6ddbd0
Show file tree
Hide file tree
Showing 12 changed files with 1,156 additions and 93 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 20
- run: yarn install --ignore-scripts
- run: yarn run ci:prettier-check
- run: yarn run lint
Expand All @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: true
matrix:
node-version: [12]
node-version: [20]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand All @@ -34,4 +34,4 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --ignore-scripts
- run: yarn run ci:test
- run: yarn run ci:test
8 changes: 4 additions & 4 deletions .github/workflows/publish-prerelease-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn install --ignore-scripts
- run: yarn build
- run: npm publish --access=public --tag beta
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
IS_CI: "true"
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
IS_CI: 'true'
8 changes: 4 additions & 4 deletions .github/workflows/publish-stable-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn install --ignore-scripts
- run: yarn build
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
IS_CI: "true"
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
IS_CI: 'true'
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Improve conflict resolver on promote

## [1.0.1] - 2021-03-30

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ npm install -g @vtex/cli-plugin-workspace
$ oclif-example COMMAND
running command...
$ oclif-example (-v|--version|version)
@vtex/cli-plugin-workspace/1.0.1 linux-x64 node-v12.21.0
@vtex/cli-plugin-workspace/1.1.0 linux-x64 node-v12.22.12
$ oclif-example --help [COMMAND]
USAGE
$ oclif-example COMMAND
Expand Down Expand Up @@ -69,7 +69,7 @@ EXAMPLES
vtex workspace delete workspaceName1 workspaceName2
```

_See code: [build/commands/workspace/delete.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/delete.ts)_
_See code: [build/commands/workspace/delete.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/delete.ts)_

## `oclif-example workspace:list`

Expand All @@ -92,11 +92,11 @@ EXAMPLES
vtex workspace ls
```

_See code: [build/commands/workspace/list.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/list.ts)_
_See code: [build/commands/workspace/list.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/list.ts)_

## `oclif-example workspace:promote`

Promotes the current workspace to master. (Only works for production workspaces.) Run [38;5;205mvtex promote --help to see how to deal with data conflicts.
Promotes the current workspace to master. (Only works for production workspaces.) Run mvtex promote --help to see how to deal with data conflicts.

```
USAGE
Expand Down Expand Up @@ -126,7 +126,7 @@ EXAMPLES
vtex promote
```

_See code: [build/commands/workspace/promote.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/promote.ts)_
_See code: [build/commands/workspace/promote.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/promote.ts)_

## `oclif-example workspace:reset [WORKSPACENAME]`

Expand All @@ -151,7 +151,7 @@ EXAMPLES
vtex workspace reset workspaceName
```

_See code: [build/commands/workspace/reset.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/reset.ts)_
_See code: [build/commands/workspace/reset.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/reset.ts)_

## `oclif-example workspace:status [WORKSPACENAME]`

Expand All @@ -173,7 +173,7 @@ EXAMPLE
vtex workspace status
```

_See code: [build/commands/workspace/status.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/status.ts)_
_See code: [build/commands/workspace/status.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/status.ts)_

## `oclif-example workspace:use WORKSPACE`

Expand Down Expand Up @@ -201,5 +201,5 @@ EXAMPLES
vtex use workspaceName
```

_See code: [build/commands/workspace/use.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/use.ts)_
_See code: [build/commands/workspace/use.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/use.ts)_
<!-- commandsstop -->
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vtex/cli-plugin-workspace",
"description": "vtex plugin workspace",
"version": "1.0.1",
"version": "1.1.0",
"bugs": "https://github.com/vtex/cli-plugin-workspace/issues",
"dependencies": {
"@oclif/command": "^1",
Expand All @@ -28,7 +28,9 @@
"ts-jest": "^25.2.1",
"ts-node": "^8",
"typescript": "^3.8.2",
"vtex": "2.111.2-beta"
"vtex-latest": "npm:[email protected]",
"vtex": "npm:[email protected]",
"@vtex/api": "npm:@vtex/[email protected]"
},
"engines": {
"node": ">=8.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/workspace/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class WorkspaceDelete extends CustomCommand {
`${ColorifyConstants.COMMAND_OR_VTEX_REF('vtex workspace delete')} workspaceName1 workspaceName2`,
]

static flags = {
static flags: oclifFlags.Input<any> = {
...CustomCommand.globalFlags,
force: oclifFlags.boolean({
char: 'f',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/workspace/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class WorkspaceReset extends CustomCommand {
`${ColorifyConstants.COMMAND_OR_VTEX_REF('vtex workspace reset')} workspaceName`,
]

static flags = {
static flags: oclifFlags.Input<any> = {
...CustomCommand.globalFlags,
production: oclifFlags.boolean({
char: 'p',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/workspace/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class WorkspaceUse extends CustomCommand {

static aliases = ['use']

static flags = {
static flags: oclifFlags.Input<any> = {
...CustomCommand.globalFlags,
production: oclifFlags.boolean({
char: 'p',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/delete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspaces } from '@vtex/api'
import { Workspaces } from 'vtex/node_modules/@vtex/api/lib/clients/Workspaces'
import chalk from 'chalk'
import { contains, flatten, tail } from 'ramda'
import { createWorkspacesClient, SessionManager, logger, promptConfirm, workspaceUse } from 'vtex'
Expand Down
25 changes: 19 additions & 6 deletions src/modules/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import {
SessionManager,
logger,
promptConfirm,
VBase,
authUrl,
workspaceUse,
COLORS,
} from 'vtex'

const { checkForConflicts } = VBase.createClient()
import { VBase } from 'vtex-latest'
import { MineWinsConflictsResolver } from '@vtex/api'

const vbase = VBase.createClient(undefined, {
timeout: 120 * 1000,
})

const { promote, get } = createWorkspacesClient()
const { account, workspace: currentWorkspace } = SessionManager.getSingleton()
const workspaceUrl = authUrl()
Expand All @@ -25,12 +30,20 @@ const throwIfIsMaster = (workspace: string) => {
}
}

/* This function is very specific to solve conflicts in the pages graphql app.
The primary conflict resolution strategy at the file level
is insufficient for safely resolving conflicts in the pages GraphQL application.
All conflicts resolved here is using a mineWins strategy at the content json level.
*/
const handleConflict = async () => {
const conflictsFound = await checkForConflicts()
// Forcing rebase to avoid conflicts
await axios.get(workspaceUrl)

if (conflictsFound) {
await axios.get(workspaceUrl)
}
// @vtex/api expects a full implementation of the client, so we need to cast it to any.
// The partial implementation is enough to solve conflicts.
const conflictsResolver = new MineWinsConflictsResolver((vbase as Partial<VBase>) as any, 'userData', '')

return conflictsResolver.resolveAll()
}

const isPromotable = async (workspace: string) => {
Expand Down
Loading

0 comments on commit a6ddbd0

Please sign in to comment.