Skip to content

Commit b32ab9c

Browse files
authored
Merge pull request #36 from rootstrap/fix/build_new_template_version_workflow
fix(build): new template version workflow
2 parents 83bc3a2 + 187d364 commit b32ab9c

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

.github/workflows/new-app-version.yml renamed to .github/workflows/new-template-version.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Starter releasing process: https://starter.obytes.com/ci-cd/app-releasing-process/
44

55
# ✍️ Description:
6-
# This workflow is used to create a new version of the app and push a new tag to the repo.
6+
# This workflow is used to create a new version of the template and push a new tag to the repo.
77
# As this workflow will push code to the repo, we set up GitHub Bot as a Git user.
88
# This Workflow need to be triggered manually from the Actions tab in the repo.
99
# 1. Choose your release type (patch, minor, major)
@@ -20,7 +20,7 @@
2020
# make sure to add it to the repo secrets with the name GH_TOKEN
2121
# Attention: Not to be confused with the GITHUB_TOKEN, this is a different token with different permissions.
2222

23-
name: New App Version
23+
name: New Template Version
2424

2525
on:
2626
workflow_dispatch:
@@ -39,6 +39,8 @@ jobs:
3939
release:
4040
name: Create New Version and push new tag
4141
runs-on: ubuntu-latest
42+
environment:
43+
name: template
4244
permissions:
4345
contents: write
4446
steps:
@@ -61,6 +63,6 @@ jobs:
6163
- name: 📦 Setup Node + PNPM + install deps
6264
uses: ./.github/actions/setup-node-pnpm-install
6365

64-
- name: 🏃‍♂️ Run App release
66+
- name: 🏃‍♂️ Run Template release
6567
run: |
6668
pnpm app-release ${{ github.event.inputs.release-type }}

cli/setup-project.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ const updatePackageInfos = async (projectName) => {
4343
type: 'git',
4444
url: 'git+https://github.com/user/repo-name.git',
4545
};
46+
47+
const appReleaseScript = packageJson.scripts['app-release'];
48+
packageJson.scripts['app-release'] = appReleaseScript.replace(
49+
'template',
50+
projectName
51+
);
4652
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
4753
};
4854

@@ -60,17 +66,54 @@ const updateProjectConfig = async (projectName) => {
6066
};
6167

6268
const updateGitHubWorkflows = (projectName) => {
63-
const upstreamToPRWorkflowPath = path.join(
64-
process.cwd(),
65-
`${projectName}/.github/workflows/upstream-to-pr.yml`
66-
);
67-
const contents = fs.readFileSync(upstreamToPRWorkflowPath, {
68-
encoding: 'utf-8',
69-
});
69+
const WORKFLOW_FILES = [
70+
{
71+
fileName: '.github/workflows/upstream-to-pr.yml',
72+
replacements: [
73+
{
74+
searchValue: UPSTREAM_REPOSITORY,
75+
replaceValue: TEMPLATE_REPOSITORY,
76+
},
77+
],
78+
},
79+
{
80+
fileName: '.github/workflows/new-template-version.yml',
81+
replacements: [
82+
{
83+
searchValue: 'new version of the template',
84+
replaceValue: 'new version of the app',
85+
},
86+
{
87+
searchValue: 'New Template Version',
88+
replaceValue: `New ${projectName} Version`,
89+
},
90+
{
91+
searchValue: 'Run Template release',
92+
replaceValue: 'Run App release',
93+
},
94+
{
95+
searchValue: /^\s*environment:\s*\n\s*name:\s*template\s*\n/m,
96+
replaceValue: '',
97+
},
98+
],
99+
},
100+
];
101+
102+
WORKFLOW_FILES.forEach(({ fileName, replacements }) => {
103+
const workflowPath = path.join(process.cwd(), `${projectName}/${fileName}`);
104+
105+
const contents = fs.readFileSync(workflowPath, {
106+
encoding: 'utf-8',
107+
});
70108

71-
const replaced = contents.replace(UPSTREAM_REPOSITORY, TEMPLATE_REPOSITORY);
109+
let replaced = contents;
72110

73-
fs.writeFileSync(upstreamToPRWorkflowPath, replaced, { spaces: 2 });
111+
replacements.forEach(({ searchValue, replaceValue }) => {
112+
replaced = replaced.replace(searchValue, replaceValue);
113+
});
114+
115+
fs.writeFileSync(workflowPath, replaced, { spaces: 2 });
116+
});
74117
};
75118

76119
const renameFiles = (projectName) => {
@@ -79,6 +122,10 @@ const renameFiles = (projectName) => {
79122
oldFileName: 'README-project.md',
80123
newFileName: 'README.md',
81124
},
125+
{
126+
oldFileName: '.github/workflows/new-template-version.yml',
127+
newFileName: '.github/workflows/new-app-version.yml',
128+
},
82129
];
83130

84131
FILES_TO_RENAME.forEach(({ oldFileName, newFileName }) => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"build:production:ios": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform ios",
2929
"build:production:android": "cross-env APP_ENV=production EXPO_NO_DOTENV=1 eas build --profile production --platform android ",
3030
"postinstall": "husky install",
31-
"app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft",
32-
"version": "pnpm run prebuild && git add .",
31+
"app-release": "cross-env SKIP_BRANCH_PROTECTION=true np --no-publish --no-cleanup --no-release-draft --message 'chore: release template v%s'",
32+
"version": "git add .",
3333
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
3434
"type-check": "tsc --noemit",
3535
"lint:translations": "eslint ./src/translations/ --fix --ext .json ",

0 commit comments

Comments
 (0)