Repository navigation
ci: support Pro in release-tag-creation action [ED-25747] #60
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
deae2ef
ci: support Pro in release-tag-creation action [ED-25747]
davseve 42cc408
Sast issues
davseve 60c08cd
ci: restrict patchPhpVersion constant to known version constants [ED-…
davseve dfbe0df
ci: default release-tag-creation plugin input to core [ED-25747]
davseve 509703d
ci: add check-release-owner action [ED-25747]
davseve df341e3
ci: remove check-release-owner action [ED-25747]
davseve 1892fd9
ci: use GitHub Contents API for fetchCoreReleaseVersion, move setOutp…
cursoragent 73fe456
ci: split update-version-files entrypoint to prevent NODE_ENV=test pr…
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
actions/release-tag-creation/elementor-tested-up-to.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { | ||
| fetchCoreReleaseVersion, | ||
| toTestedUpToVersion, | ||
| } from './elementor-tested-up-to.ts'; | ||
|
|
||
| const HTTP_OK = 200; | ||
| const HTTP_NOT_FOUND = 404; | ||
|
|
||
| function mockFetchResponse(body: string, status = HTTP_OK) { | ||
| const fetchMock = vi.fn().mockResolvedValue(new Response(body, { status })); | ||
| vi.stubGlobal('fetch', fetchMock); | ||
| return fetchMock; | ||
| } | ||
|
|
||
| describe('toTestedUpToVersion', () => { | ||
| it.each([ | ||
| ['4.3.0', '4.3.0'], | ||
| ['4.4.0-beta2', '4.4.0'], | ||
| ['4.10.12', '4.10.12'], | ||
| ])('%s → %s', (coreVersion, expected) => { | ||
| expect(toTestedUpToVersion(coreVersion)).toBe(expected); | ||
| }); | ||
|
|
||
| it('throws on an invalid version', () => { | ||
| expect(() => toTestedUpToVersion('4.3')).toThrow('not valid semver'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('fetchCoreReleaseVersion', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it.each(['stable', 'beta'] as const)( | ||
| 'reads Version from Core release/%s via GitHub Contents API', | ||
| async (channel) => { | ||
| const fetchMock = mockFetchResponse( | ||
| ['<?php', '/**', ' * Version: 4.4.0-beta2', ' */'].join('\n'), | ||
| ); | ||
|
|
||
| await expect(fetchCoreReleaseVersion(channel)).resolves.toBe( | ||
| '4.4.0-beta2', | ||
| ); | ||
| expect(fetchMock).toHaveBeenCalledWith( | ||
| `https://api.github.com/repos/elementor/elementor/contents/elementor.php?ref=release/${channel}`, | ||
| { | ||
| headers: { | ||
| Accept: 'application/vnd.github.raw', | ||
| 'User-Agent': 'elementor-editor-github-actions', | ||
| }, | ||
| }, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it('includes Authorization header when token is provided', async () => { | ||
| const fetchMock = mockFetchResponse( | ||
| ['<?php', '/**', ' * Version: 4.4.0-beta2', ' */'].join('\n'), | ||
| ); | ||
| const token = 'ghp_test123'; | ||
|
|
||
| await expect(fetchCoreReleaseVersion('stable', token)).resolves.toBe( | ||
| '4.4.0-beta2', | ||
| ); | ||
| expect(fetchMock).toHaveBeenCalledWith( | ||
| 'https://api.github.com/repos/elementor/elementor/contents/elementor.php?ref=release/stable', | ||
| { | ||
| headers: { | ||
| Accept: 'application/vnd.github.raw', | ||
| Authorization: 'Bearer ghp_test123', | ||
| 'User-Agent': 'elementor-editor-github-actions', | ||
| }, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('throws when the request fails', async () => { | ||
| mockFetchResponse('Not Found', HTTP_NOT_FOUND); | ||
|
|
||
| await expect(fetchCoreReleaseVersion('beta')).rejects.toThrow( | ||
| 'HTTP 404', | ||
| ); | ||
| }); | ||
|
|
||
| it('throws when the Version header is missing', async () => { | ||
| mockFetchResponse('<?php // no header'); | ||
|
|
||
| await expect(fetchCoreReleaseVersion('stable')).rejects.toThrow( | ||
| 'No "Version:" header found', | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import semver from 'semver'; | ||
| import { parseHeaderField } from '@elementor/editor-github-actions-utils'; | ||
|
|
||
| export type ReleaseChannel = 'stable' | 'beta'; | ||
|
|
||
| export function toTestedUpToVersion(coreVersion: string): string { | ||
| const parsed = semver.parse(coreVersion); | ||
|
|
||
| if (!parsed) { | ||
| throw new Error(`Core version "${coreVersion}" is not valid semver.`); | ||
| } | ||
|
|
||
| return `${String(parsed.major)}.${String(parsed.minor)}.${String(parsed.patch)}`; | ||
| } | ||
|
|
||
| export async function fetchCoreReleaseVersion( | ||
| channel: ReleaseChannel, | ||
| token?: string, | ||
| ): Promise<string> { | ||
| const ref = `release/${channel}`; | ||
| const url = `https://api.github.com/repos/elementor/elementor/contents/elementor.php?ref=${ref}`; | ||
|
|
||
| const headers: HeadersInit = { | ||
| Accept: 'application/vnd.github.raw', | ||
| 'User-Agent': 'elementor-editor-github-actions', | ||
| }; | ||
|
|
||
| if (token) { | ||
| headers['Authorization'] = `Bearer ${token}`; | ||
| } | ||
|
|
||
| const response = await fetch(url, { headers }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to fetch Core plugin file from ${url}: HTTP ${String(response.status)}`, | ||
| ); | ||
| } | ||
|
|
||
| const version = parseHeaderField(await response.text(), 'Version'); | ||
|
|
||
| if (!version) { | ||
| throw new Error(`No "Version:" header found in ${url}`); | ||
| } | ||
|
|
||
| return version; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { resolvePluginConfig } from './plugin-config.ts'; | ||
|
|
||
| describe('resolvePluginConfig', () => { | ||
| it('resolves Core to elementor.php with readme updates', () => { | ||
| expect(resolvePluginConfig('core')).toEqual({ | ||
| pluginFile: 'elementor.php', | ||
| versionConstant: 'ELEMENTOR_VERSION', | ||
| updateReadme: true, | ||
| updateElementorTestedUpTo: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('resolves Pro to elementor-pro.php with Elementor tested up to updates', () => { | ||
| expect(resolvePluginConfig('pro')).toEqual({ | ||
| pluginFile: 'elementor-pro.php', | ||
| versionConstant: 'ELEMENTOR_PRO_VERSION', | ||
| updateReadme: false, | ||
| updateElementorTestedUpTo: true, | ||
| }); | ||
| }); | ||
|
|
||
| it.each(['', 'Core', 'elementor'])('throws on "%s"', (plugin) => { | ||
| expect(() => resolvePluginConfig(plugin)).toThrow( | ||
| 'plugin must be "core" or "pro"', | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { VersionConstant } from '@elementor/editor-github-actions-utils'; | ||
|
|
||
| export type Plugin = 'core' | 'pro'; | ||
|
|
||
| export type PluginConfig = { | ||
| pluginFile: string; | ||
| versionConstant: VersionConstant; | ||
| updateReadme: boolean; | ||
| updateElementorTestedUpTo: boolean; | ||
| }; | ||
|
|
||
| const PLUGIN_CONFIGS: Record<Plugin, PluginConfig> = { | ||
| core: { | ||
| pluginFile: 'elementor.php', | ||
| versionConstant: 'ELEMENTOR_VERSION', | ||
| updateReadme: true, | ||
| updateElementorTestedUpTo: false, | ||
| }, | ||
| pro: { | ||
| pluginFile: 'elementor-pro.php', | ||
| versionConstant: 'ELEMENTOR_PRO_VERSION', | ||
| updateReadme: false, | ||
| updateElementorTestedUpTo: true, | ||
| }, | ||
| }; | ||
|
|
||
| export function resolvePluginConfig(plugin: string): PluginConfig { | ||
| if (plugin !== 'core' && plugin !== 'pro') { | ||
| throw new Error(`plugin must be "core" or "pro", got "${plugin}"`); | ||
| } | ||
| return PLUGIN_CONFIGS[plugin]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { run } from './update-version-files.ts'; | ||
|
|
||
| void run(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the value is "koko"?