Skip to content
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

feat: update VERSION file in PHP repo if it exists #2153

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/strategies/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Changelog} from '../updaters/changelog';
// PHP Specific.
import {RootComposerUpdatePackages} from '../updaters/php/root-composer-update-packages';
import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base';
import {DefaultUpdater} from '../updaters/default';
import {Update} from '../update';
import {VersionsMap} from '../version';

Expand Down Expand Up @@ -67,6 +68,21 @@ export class PHP extends BaseStrategy {
}),
});

const contents = await this.github.getFileContentsOnBranch(
bshaffer marked this conversation as resolved.
Show resolved Hide resolved
this.addPath('VERSION'),
this.targetBranch
);

// update VERSION file
updates.push({
path: this.addPath('VERSION'),
createIfMissing: false,
cachedFileContents: contents,
bshaffer marked this conversation as resolved.
Show resolved Hide resolved
updater: new DefaultUpdater({
version,
}),
});

return updates;
}
}
11 changes: 9 additions & 2 deletions test/strategies/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import {expect} from 'chai';
import {GitHub} from '../../src/github';
import {PHP} from '../../src/strategies/php';
import * as sinon from 'sinon';
import {assertHasUpdate} from '../helpers';
import {assertHasUpdate, buildGitHubFileRaw} from '../helpers';
import {buildMockConventionalCommit} from '../helpers';
import {TagName} from '../../src/util/tag-name';
import {Version} from '../../src/version';
import {Changelog} from '../../src/updaters/changelog';
import {RootComposerUpdatePackages} from '../../src/updaters/php/root-composer-update-packages';
import {DefaultUpdater} from '../../src/updaters/default';

const sandbox = sinon.createSandbox();

Expand All @@ -38,12 +39,17 @@ const COMMITS = [

describe('PHP', () => {
let github: GitHub;
let getFileStub: sinon.SinonStub;
beforeEach(async () => {
github = await GitHub.create({
owner: 'googleapis',
repo: 'php-test-repo',
defaultBranch: 'main',
});
getFileStub = sandbox.stub(github, 'getFileContentsOnBranch');
getFileStub
.withArgs('VERSION', 'main')
.resolves(buildGitHubFileRaw('1.2.3'));
});
afterEach(() => {
sandbox.restore();
Expand Down Expand Up @@ -95,9 +101,10 @@ describe('PHP', () => {
latestRelease
);
const updates = release!.updates;
expect(updates).lengthOf(2);
expect(updates).lengthOf(3);
assertHasUpdate(updates, 'CHANGELOG.md', Changelog);
assertHasUpdate(updates, 'composer.json', RootComposerUpdatePackages);
assertHasUpdate(updates, 'VERSION', DefaultUpdater);
});
});
});
Loading