feat: add automated release workflow #2
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
name: Release from React Native | ||
on: | ||
repository_dispatches: | ||
types: [release] | ||
# NOTE: Changes here need to be reflected in release.yaml | ||
jobs: | ||
publish_template_automation: | ||
runs-on: ubuntu-latest | ||
env: | ||
VERSION: ${{ github.events.client_payload.version }} | ||
steps: | ||
- name: Safeguard against branch name | ||
run: | | ||
if [[ "$BRANCH" != *-stable ]]; then | ||
echo "Error: This workflow can only be executed from a branch ending with '-stable'." | ||
exit 1 | ||
fi | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
- name: Move to MAJOR.MINOR-stable or create if it doesn't exist | ||
run: | | ||
VERSION=$(grep -E '\d+\.\d+' <<< "$VERSION" | awk '{ print "branch="$0"-stable" }') | ||
if ! git ls-remote -q --exit-code --heads origin $VERSION > /dev/null; then | ||
echo "Creating missing release branch \"$VERSION\"" | ||
git checkout -B "$VERSION" | ||
git push --set-upstream origin "$VERSION" | ||
else | ||
git checkout "$VERSION" | ||
fi | ||
- name: Setup node.js | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 18 | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Update versions to input one | ||
run: node ./scripts/updateTemplateVersion.js "$VERSION" | ||
- name: Update template/package.json to nightly react-native + @react-native | ||
run: node ./scripts/updateReactNativeVersion.js "$VERSION" | ||
- name: Create corresponding commit & git tag | ||
run: | | ||
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: | | ||
if [[ "$VERSION" == *"rc"* ]]; then | ||
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 | ||
fi | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||