From 187d364ec7bf68b1569a209b9a8c62c808a198c1 Mon Sep 17 00:00:00 2001 From: Lucas Raposeiras Date: Wed, 28 Aug 2024 01:12:42 +0200 Subject: [PATCH] fix(build): new template version workflow --- ...p-version.yml => new-template-version.yml} | 8 ++- cli/setup-project.js | 65 ++++++++++++++++--- package.json | 4 +- 3 files changed, 63 insertions(+), 14 deletions(-) rename .github/workflows/{new-app-version.yml => new-template-version.yml} (91%) diff --git a/.github/workflows/new-app-version.yml b/.github/workflows/new-template-version.yml similarity index 91% rename from .github/workflows/new-app-version.yml rename to .github/workflows/new-template-version.yml index a08995b4d..552fe9cc4 100644 --- a/.github/workflows/new-app-version.yml +++ b/.github/workflows/new-template-version.yml @@ -3,7 +3,7 @@ # Starter releasing process: https://starter.obytes.com/ci-cd/app-releasing-process/ # ✍️ Description: -# This workflow is used to create a new version of the app and push a new tag to the repo. +# This workflow is used to create a new version of the template and push a new tag to the repo. # As this workflow will push code to the repo, we set up GitHub Bot as a Git user. # This Workflow need to be triggered manually from the Actions tab in the repo. # 1. Choose your release type (patch, minor, major) @@ -20,7 +20,7 @@ # make sure to add it to the repo secrets with the name GH_TOKEN # Attention: Not to be confused with the GITHUB_TOKEN, this is a different token with different permissions. -name: New App Version +name: New Template Version on: workflow_dispatch: @@ -39,6 +39,8 @@ jobs: release: name: Create New Version and push new tag runs-on: ubuntu-latest + environment: + name: template permissions: contents: write steps: @@ -61,6 +63,6 @@ jobs: - name: 📦 Setup Node + PNPM + install deps uses: ./.github/actions/setup-node-pnpm-install - - name: 🏃‍♂️ Run App release + - name: 🏃‍♂️ Run Template release run: | pnpm app-release ${{ github.event.inputs.release-type }} diff --git a/cli/setup-project.js b/cli/setup-project.js index a4a7d9246..c7b84dfed 100755 --- a/cli/setup-project.js +++ b/cli/setup-project.js @@ -43,6 +43,12 @@ const updatePackageInfos = async (projectName) => { type: 'git', url: 'git+https://github.com/user/repo-name.git', }; + + const appReleaseScript = packageJson.scripts['app-release']; + packageJson.scripts['app-release'] = appReleaseScript.replace( + 'template', + projectName + ); fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 }); }; @@ -60,17 +66,54 @@ const updateProjectConfig = async (projectName) => { }; const updateGitHubWorkflows = (projectName) => { - const upstreamToPRWorkflowPath = path.join( - process.cwd(), - `${projectName}/.github/workflows/upstream-to-pr.yml` - ); - const contents = fs.readFileSync(upstreamToPRWorkflowPath, { - encoding: 'utf-8', - }); + const WORKFLOW_FILES = [ + { + fileName: '.github/workflows/upstream-to-pr.yml', + replacements: [ + { + searchValue: UPSTREAM_REPOSITORY, + replaceValue: TEMPLATE_REPOSITORY, + }, + ], + }, + { + fileName: '.github/workflows/new-template-version.yml', + replacements: [ + { + searchValue: 'new version of the template', + replaceValue: 'new version of the app', + }, + { + searchValue: 'New Template Version', + replaceValue: `New ${projectName} Version`, + }, + { + searchValue: 'Run Template release', + replaceValue: 'Run App release', + }, + { + searchValue: /^\s*environment:\s*\n\s*name:\s*template\s*\n/m, + replaceValue: '', + }, + ], + }, + ]; + + WORKFLOW_FILES.forEach(({ fileName, replacements }) => { + const workflowPath = path.join(process.cwd(), `${projectName}/${fileName}`); + + const contents = fs.readFileSync(workflowPath, { + encoding: 'utf-8', + }); - const replaced = contents.replace(UPSTREAM_REPOSITORY, TEMPLATE_REPOSITORY); + let replaced = contents; - fs.writeFileSync(upstreamToPRWorkflowPath, replaced, { spaces: 2 }); + replacements.forEach(({ searchValue, replaceValue }) => { + replaced = replaced.replace(searchValue, replaceValue); + }); + + fs.writeFileSync(workflowPath, replaced, { spaces: 2 }); + }); }; const renameFiles = (projectName) => { @@ -79,6 +122,10 @@ const renameFiles = (projectName) => { oldFileName: 'README-project.md', newFileName: 'README.md', }, + { + oldFileName: '.github/workflows/new-template-version.yml', + newFileName: '.github/workflows/new-app-version.yml', + }, ]; FILES_TO_RENAME.forEach(({ oldFileName, newFileName }) => { diff --git a/package.json b/package.json index 23cf6e4d3..ed3c2877c 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios", "build:production:android": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform android ", "postinstall": "husky install", - "app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft", - "version": "pnpm run prebuild && git add .", + "app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft --message 'chore: release template v%s'", + "version": "git add .", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "type-check": "tsc --noemit", "lint:translations": "eslint ./src/translations/ --fix --ext .json ",