-
Notifications
You must be signed in to change notification settings - Fork 61
feat: create releases where PATCH doesn't have to match react-native #43
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,18 @@ on: | |
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "The version of the template we want to release. For example 0.75.0-rc.0" | ||
| description: "The version of the react-native we the template to use in this release. For example 0.75.0-rc.0" | ||
| required: true | ||
| type: string | ||
| is_latest_on_npm: | ||
| description: "Whether we want to tag this template release as `latest` on NPM" | ||
| required: true | ||
| type: boolean | ||
| default: false | ||
| dry_run: | ||
| description: "Run without making persistent changes to git or npm" | ||
| type: boolean | ||
| default: true | ||
|
|
||
| jobs: | ||
| publish_template: | ||
|
|
@@ -30,35 +34,37 @@ jobs: | |
| with: | ||
| node-version: 18 | ||
| registry-url: 'https://registry.npmjs.org' | ||
| - name: Determine new template version | ||
| run: echo "VERSION=$(./scripts/bumpedTemplateVersion.sh \"${{ inputs.version }}\")" >> $GITHUB_ENV | ||
blakef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Update versions to input one | ||
| run: node ./scripts/updateTemplateVersion.js "${{ inputs.version }}" | ||
| run: node ./scripts/updateTemplateVersion.js $VERSION | ||
| - name: Update template/package.json to nightly react-native + @react-native | ||
| run: node ./scripts/updateReactNativeVersion.js "${{ inputs.version }}" | ||
| - name: Create corresponding commit & git tag | ||
| run: | | ||
| VERSION="${{ inputs.version }}" | ||
| git config --global user.name 'React Native Bot' | ||
| git config --global user.email '[email protected]' | ||
| git commit -am "Bumping template to $VERSION" | ||
| git push | ||
| git tag $VERSION | ||
| git push --tags | ||
| GIT=$([ "${{ inputs.dry_run }}" = "true" ] && "echo git" || "git"; | ||
blakef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $GIT config --global user.name 'React Native Bot' | ||
| $GIT config --global user.email '[email protected]' | ||
| $GIT commit -am "Bumping template to $VERSION" | ||
| $GIT push | ||
| $GIT tag $VERSION | ||
| $GIT push --tags | ||
| - name: Publish NPM | ||
| run: npm publish | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Set NPM tags | ||
| run: | | ||
| VERSION="${{ inputs.version }}" | ||
| NPM=$([ "${{ inputs.dry_run }}" = "true" ] && "echo npm" || "npm"; | ||
| IS_LATEST_ON_NPM="${{ inputs.is_latest_on_npm }}" | ||
| if [[ "$IS_LATEST_ON_NPM" == "true" ]]; then | ||
| npm dist-tag add @react-native-community/template@$VERSION latest | ||
| $NPM dist-tag add @react-native-community/template@$VERSION latest | ||
| fi | ||
| if [[ "$VERSION" == *"rc"* ]]; then | ||
| npm dist-tag add @react-native-community/template@$VERSION next | ||
| $NPM dist-tag add @react-native-community/template@$VERSION next | ||
| fi | ||
| if [[ "$GITHUB_REF_NAME" == *"-stable" ]]; then | ||
| npm dist-tag add @react-native-community/template@$VERSION $GITHUB_REF_NAME | ||
| $NPM dist-tag add @react-native-community/template@$VERSION $GITHUB_REF_NAME | ||
| fi | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
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,9 @@ | ||
| /** @type {import('jest').Config} */ | ||
| const config = { | ||
| coverageProvider: "v8", | ||
| testMatch: [ | ||
| "**/__tests__/*.js", | ||
| ], | ||
| }; | ||
|
|
||
| module.exports = config; |
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
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,30 @@ | ||
| const {execSync} = require('child_process'); | ||
| const semver = require('semver'); | ||
|
|
||
| function run(version) { | ||
| return execSync(`./bumpedTemplateVersion.sh ${version}`, { cwd: 'scripts', stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim(); | ||
| } | ||
|
|
||
| describe('bumpTemplateVersion.sh', () => { | ||
|
|
||
| it('nightlies stay the same', () => { | ||
| expect(run('0.75.0-nightly-20240606-4324f0874')).toEqual('0.75.0-nightly-20240606-4324f0874'); | ||
| }); | ||
|
|
||
| it('release candidates appended with a sha', () => { | ||
| expect(run('0.74.0-rc.3')).toMatch(/0\.74\.0-rc\.3-.+/); | ||
| }); | ||
|
|
||
| it('assumed it is the first version when no matching MAJOR.MINOR', () => { | ||
| const versionShouldNeverExist = '1111.0.1'; | ||
| expect(run(versionShouldNeverExist)).toEqual('1111.0.0'); | ||
| }); | ||
|
|
||
| it('bumps the patch if a version of the template already exists', async () => { | ||
| // This sucks I know: | ||
| const {version} = await fetch('https://registry.npmjs.com/@react-native-community/template/latest').then(resp => resp.json()); | ||
| const {major, minor, patch} = semver.parse(version); | ||
| expect(run(`${major}.${minor}.${patch}`)).toEqual(`${major}.${minor}.${patch+1}`); | ||
| }); | ||
|
|
||
| }); |
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,50 @@ | ||
| #!/bin/bash | ||
|
|
||
| # What this does: | ||
| # 1. Take the version of react, use the MAJOR.MINOR | ||
| # - /nightly/ -> MAJOR.MINOR.PATCH-nightly-YYYYNN-HASH | ||
| # - /-rc.N/ -> MAJOR.MINOR.PATCH-rc.N-HASH | ||
| # - ELSE: continue | ||
| # 2. Look for the latest version of the template with that MAJOR.MINOR | ||
| # - No version -> then set to MAJOR.MINOR.0 | ||
| # - MAJOR.MINOR.PATCH -> MAJOR.MINOR.PATCH+1 | ||
blakef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| log() { | ||
| echo "$@" >&2 | ||
| } | ||
|
|
||
| if [[ $# != 1 ]]; then | ||
| log "USAGE: bumpTemplateVersion.sh <react native version>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ $1 =~ -rc\.[0-9]+ ]]; then | ||
| log "Release candidate" | ||
| # Append a sha, so if we need to re-release for a RC we don't conflict | ||
| echo $1-$(git rev-parse --short HEAD) | ||
blakef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $1 =~ -nightly- ]]; then | ||
| log "Nightly candidate" | ||
| # Once a day, we're not going to get conflicts using the given nightly tag | ||
| echo $1 | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Find current version of template that matches this version of react-native. | ||
| if [[ $1 =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then | ||
| MAJOR_MINOR=$(awk -F'.' '{ print $1"."$2 }' <<< $1) | ||
| CURRENT_VERSION=$(npm show --json "@react-native-community/template@^$MAJOR_MINOR") | ||
blakef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [ $? -ne 0 ]; then | ||
| echo "$MAJOR_MINOR.0"; | ||
| exit 0; | ||
| fi | ||
| # Bump PATCH | ||
| PUBLISHED=$(jq -r 'last | .version' <<< $CURRENT_VERSION | awk -F'.' '{ print $1"."$2"."($3+1) }') | ||
| echo $PUBLISHED; | ||
| exit 0 | ||
| fi | ||
|
|
||
| log "Unknown type of release: $RN_VERSION" | ||
| exit 1 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.