Skip to content

Commit

Permalink
feat: add force param to sync workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Dec 16, 2024
1 parent d9c01c2 commit 8d422f7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/actions/update-sdk-schema/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
allowedScopes:
description: "List of change scopes to allow, comma separated. If left empty, all scopes are allowed."
default: ""
force:
description: "Whenever to force update to given tag, even if it was already updated before"
default: "false"
runs:
using: 'node20'
main: 'dist/index.js'
2 changes: 2 additions & 0 deletions .github/actions/update-sdk-schema/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Config {
owner: string
repo: string
allowedScopes: string[]
force: boolean
}

export function getConfig(): Config {
Expand All @@ -20,6 +21,7 @@ export function getConfig(): Config {
generateCommand: core.getInput('generateCommand'),
githubToken: core.getInput('githubToken'),
preRelease: core.getInput('preRelease') === 'true',
force: core.getInput('force') === 'true',
owner,
repo,
allowedScopes: core
Expand Down
18 changes: 18 additions & 0 deletions .github/actions/update-sdk-schema/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ interface ListReleasesBetweenParams {
toTag: string
}

interface GetReleaseParams {
tag: string
octokit: GitHubClient
config: Pick<Config, 'owner' | 'repo'>
}

export async function getRelease({ config, tag, octokit }: GetReleaseParams): Promise<Release> {
const { data } = await withRetry(() =>
octokit.rest.repos.getReleaseByTag({
owner: config.owner,
repo: config.repo,
tag,
})
)

return data
}

/**
* Lists releases between given tags
* It is worth noting that for `fromTag` we perform `gt` comparison, while for `toTag` we perform `lte`
Expand Down
29 changes: 23 additions & 6 deletions .github/actions/update-sdk-schema/update-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { startPreRelease } from './changesets'
import { Config, getConfig } from './config'
import { updateSchemaForTag } from './update-schema-for-tag'
import { getLatestSchemaVersion, writeSchemaVersion } from './schema-version'
import { listReleasesBetween } from './github'
import { getRelease, listReleasesBetween } from './github'

interface UpdateSchemaParams {
config: Config
Expand All @@ -22,12 +22,23 @@ export async function updateSchema({ config, tag, packageName, preReleaseTag = '
}

const octokit = getOctokit(config.githubToken)
// v1.0.0 is the first OpenAPI release that was created
const schemaVersion = getLatestSchemaVersion() ?? 'v1.0.0'
const releases = await listReleasesBetween({ octokit, config, fromTag: schemaVersion, toTag: tag })

for (const release of releases) {
if (config.force) {
const release = await getRelease({
config,
tag,
octokit,
})

await updateSchemaForTag(release.tag_name, octokit, packageName, config, cwd)
} else {
// v1.0.0 is the first OpenAPI release that was created
const schemaVersion = getLatestSchemaVersion() ?? 'v1.0.0'
const releases = await listReleasesBetween({ octokit, config, fromTag: schemaVersion, toTag: tag })

for (const release of releases) {
await updateSchemaForTag(release.tag_name, octokit, packageName, config, cwd)
}
}

writeSchemaVersion(tag, cwd)
Expand All @@ -40,7 +51,13 @@ async function main() {
const packageJson = JSON.parse(fs.readFileSync(path.join('./package.json'), 'utf-8'))
const preReleaseTag = core.getInput('preReleaseTag')

await updateSchema({ config, tag, packageName: packageJson.name, preReleaseTag, cwd: process.cwd() })
await updateSchema({
config,
tag,
packageName: packageJson.name,
preReleaseTag,
cwd: process.cwd(),
})
} catch (err) {
core.setFailed(err as Error)
}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/update-server-side-sdk-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ on:
required: false
type: string
default: ""
force:
description: "Whenever to force update to given tag, even if it was already updated before"
default: false
type: boolean
required: false

secrets:
APP_PRIVATE_KEY:
Expand Down Expand Up @@ -123,6 +128,7 @@ jobs:
preRelease: '${{ inputs.pre-release }}'
allowedScopes: ${{ inputs.allowed-scopes }}
preReleaseTag: '${{ inputs.pre-release-tag }}'
force: '${{ inputs.force }}'

- name: Add & Commit
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ The workflow accepts the following input parameters:
| `pre-release` | No | Bool | `false` | Whether to start a pre-release changeset flow |
| `pre-release-tag` | No | String | `test` | Tag suffix used for pre-releases |
| `allowed-scopes` | No | String | "" | List of change scopes to allow, comma separated. If left empty, all scopes are allowed. |
| `force` | No | Bool | `false` | "Whenever to force update to given tag, even if it was already updated before" |

#### Workflow Secrets

Expand Down

0 comments on commit 8d422f7

Please sign in to comment.