Skip to content

Commit

Permalink
feat: major version tags (#682)
Browse files Browse the repository at this point in the history
* refactor: rename files

This consolidates getNodeVersion into another file and renames the set-version-output function to have a .js extension so we don't need to have weird `npm run lint` carveouts for it

* test: more test coverage

* refactor: use core function for output setting

This pattern for setting outputs is now deprecated

* fix: whoops

* refactor: use semver to parse out major version

we were previously using a zero-deps approach but now that we need to install deps for the set-version-output step, we might as well use a safer approach here.

* refactor: add ability to grab major version + test

this will set up some upcoming tagging changes

* feat: create file for tagging version

* docs: small update

* Revert "refactor: add ability to grab major version + test"

This reverts commit 0fc0fe2.

* revert(kinda): use semver major instead

* refactor: use vanilla imports where possible

simple-git isn't really being super helpful here, so we might as well use a vanilla node function instead. i struggled to write tests so not gonna use our `getPkgVersion` function either since importing directly from package.json is just fine.

* chore: do a clean install + build before version bump

* docs: update github docs URLs

* docs: update MAINTAINERS guide

i feel like this flow is better, tagging a beta tripped me up the first time

* feat: surface major version tag in GHA onboarding

we should surface the v8 tag in the github actions that we create. this required a decent refactor to consolidate our major version retrieval logic. a bunch of snapshots had to be updated too.

* feat: surface major version tag in our docs

* chore: small JSDoc update

* fix: don't add major tag if prerelease

* fix: cmon dude

* refactor: use logger
  • Loading branch information
kanadgupta authored Nov 29, 2022
1 parent 0e4644a commit dc103c0
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"overrides": [
{
"files": ["bin/set-version-output", "config/*.js"],
"files": ["bin/set-version-output.js", "bin/set-major-version-tag.js", "config/*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# our package version and our Node.js version.
- name: Retrieve version values
id: rdme-version
run: ./bin/set-version-output
run: ./bin/set-version-output.js

# Next, we use this output to do a few find/replaces!
- name: Find and replace Node.js version placeholders
Expand Down
10 changes: 5 additions & 5 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The next step is to push these changes to GitHub:

```sh
git push # pushes the code
git push --tags # pushes the tags
git push --tags -f # pushes the tags
```

Once the code and tags are pushed to GitHub, [create a new release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release) so the latest tag is surfaced in [the GitHub Marketplace listing](https://github.com/marketplace/actions/rdme-sync-to-readme).
Expand All @@ -30,14 +30,14 @@ Auto-generating release notes is sufficient, but I like to summarize the changes

## Publishing to `npm` :rocket:

Finally, publish the changes to `npm`. If you're publishing to the default [distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages) (i.e., `latest`), you can run the following:
Finally, publish the changes to `npm`. If you're publishing to a non-standard [distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages) for prelease purposes or otherwise (e.g., `alpha`, `beta`, `next`, etc.), you can run the following:

```sh
npm publish
npm publish --tag <tag>
```

If you're publishing to another [distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages) for prelease purposes or otherwise (e.g., `alpha`, `beta`, `next`, etc.), include the tag like so:
If you're publishing to the default [distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages) (i.e., `latest`), you can omit the `--tag` flag like so:

```sh
npm publish --tag <tag>
npm publish
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Once installed in your project, you can use the `npx` prefix (which is included
npx rdme openapi:validate [file]
```

To ensure you're getting the latest features and security updates, we recommend using a tool like [Dependabot](https://docs.github.com/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates) to keep `rdme` (and your other dependencies) up-to-date.
To ensure you're getting the latest features and security updates, we recommend using a tool like [Dependabot](https://docs.github.com/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates) to keep `rdme` (and your other dependencies) up-to-date.

### Authentication

Expand Down Expand Up @@ -117,7 +117,7 @@ rdme openapi --github

This will run through the `openapi` command, ask you a few quick questions, and then automatically create a fully functional GitHub Actions workflow file for you. 🪄

You can see examples featuring the latest version in [our docs](https://docs.readme.com/docs/rdme#github-actions-examples). We recommend [configuring Dependabot to keep your actions up-to-date](https://docs.github.com/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/keeping-your-actions-up-to-date-with-dependabot).
You can see examples featuring the latest version in [our docs](https://docs.readme.com/docs/rdme#github-actions-examples). We recommend [configuring Dependabot to keep your actions up-to-date](https://docs.github.com/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot).

## Usage

Expand Down
6 changes: 3 additions & 3 deletions __tests__/cmds/docs/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs ./__tests__/__fixtures__/docs/new-docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs ./__tests__/__fixtures__/docs/new-docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs ./__tests__/__fixtures__/docs/new-docs --key=\${{ secrets.README_API_KEY }} --version=1.0.1
"
Expand Down
14 changes: 7 additions & 7 deletions __tests__/cmds/openapi/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --version=1.0.0 --create
"
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --version=1.0.1 --create
"
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1
"
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1
"
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1
"
Expand Down Expand Up @@ -240,7 +240,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi petstore.json --key=\${{ secrets.README_API_KEY }} --id=1 --workingDirectory=./__tests__/__fixtures__/relative-ref-oas
"
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=spec2
"
Expand Down
8 changes: 4 additions & 4 deletions __tests__/cmds/openapi/__snapshots__/validate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json
"
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate petstore.json --workingDirectory=./__tests__/__fixtures__/relative-ref-oas
"
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json
"
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json
"
Expand Down
4 changes: 2 additions & 2 deletions __tests__/helpers/get-gha-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function before(writeFileSyncCb) {

process.env.TEST_RDME_CREATEGHA = 'true';

const spy = jest.spyOn(getPkgVersion, 'getPkgVersion');
spy.mockReturnValue(Promise.resolve('7.8.9'));
const spy = jest.spyOn(getPkgVersion, 'getMajorPkgVersion');
spy.mockReturnValue(Promise.resolve(7));
}

/**
Expand Down
32 changes: 16 additions & 16 deletions __tests__/lib/__snapshots__/createGHA.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`changelogs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: changelogs ./changelogs --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`changelogs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: changelogs ./changelogs/rdme.md --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`changelogs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: changelogs ./changelogs --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`changelogs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: changelogs ./changelogs/rdme.md --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`custompages\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: custompages ./custompages --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -240,7 +240,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`custompages\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: custompages ./custompages/rdme.md --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`custompages\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: custompages ./custompages --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -322,7 +322,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`custompages\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: custompages ./custompages/rdme.md --key=\${{ secrets.README_API_KEY }}
"
Expand Down Expand Up @@ -363,7 +363,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -404,7 +404,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs ./docs/rdme.md --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -445,7 +445,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -486,7 +486,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`docs\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: docs ./docs/rdme.md --key=\${{ secrets.README_API_KEY }} --version=1.0.0
"
Expand Down Expand Up @@ -527,7 +527,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi petstore.json --key=\${{ secrets.README_API_KEY }} --id=spec_id
"
Expand Down Expand Up @@ -568,7 +568,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi petstore.json --key=\${{ secrets.README_API_KEY }} --id=spec_id
"
Expand Down Expand Up @@ -605,7 +605,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate petstore.json
"
Expand Down Expand Up @@ -642,7 +642,7 @@ jobs:
uses: actions/checkout@v3
- name: Run \`openapi:validate\` command 🚀
uses: readmeio/rdme@7.8.9
uses: readmeio/rdme@v7
with:
rdme: openapi:validate petstore.json
"
Expand Down
15 changes: 5 additions & 10 deletions __tests__/lib/createGHA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import DocsCommand from '../../src/cmds/docs';
import OpenAPICommand from '../../src/cmds/openapi';
import OpenAPIValidateCommand from '../../src/cmds/openapi/validate';
import configstore from '../../src/lib/configstore';
import createGHA, {
getConfigStoreKey,
getGHAFileName,
getGitData,
getMajorRdmeVersion,
git,
} from '../../src/lib/createGHA';
import createGHA, { getConfigStoreKey, getGHAFileName, getGitData, git } from '../../src/lib/createGHA';
import { getMajorPkgVersion } from '../../src/lib/getPkgVersion';
import { after, before } from '../helpers/get-gha-setup';
import getGitRemoteMock from '../helpers/get-git-mock';
import ghaWorkflowSchema from '../helpers/github-workflow-schema.json';
Expand Down Expand Up @@ -130,7 +125,7 @@ describe('#createGHA', () => {

const repoRoot = process.cwd();

configstore.set(getConfigStoreKey(repoRoot), (await getMajorRdmeVersion()) - 1);
configstore.set(getConfigStoreKey(repoRoot), (await getMajorPkgVersion()) - 1);

return expect(createGHA('', cmd, command.args, opts)).resolves.toMatch(
'Your GitHub Actions workflow file has been created!'
Expand All @@ -153,7 +148,7 @@ describe('#createGHA', () => {
)
);

expect(configstore.get(getConfigStoreKey(repoRoot))).toBe(await getMajorRdmeVersion());
expect(configstore.get(getConfigStoreKey(repoRoot))).toBe(await getMajorPkgVersion());
});

it('should not run if not a repo', () => {
Expand All @@ -175,7 +170,7 @@ describe('#createGHA', () => {
it('should not run if user previously declined to set up GHA for current directory + pkg version', async () => {
const repoRoot = process.cwd();

configstore.set(getConfigStoreKey(repoRoot), await getMajorRdmeVersion());
configstore.set(getConfigStoreKey(repoRoot), await getMajorPkgVersion());

return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!');
});
Expand Down
Loading

0 comments on commit dc103c0

Please sign in to comment.