Skip to content

Commit 0a1efe7

Browse files
committed
Merge branch 'master' into feat/query-factory
2 parents 390b046 + 201e849 commit 0a1efe7

34 files changed

+2726
-1588
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# 🔗 Links:
2+
# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/project-workflows/sync-with-template.yml
3+
4+
# ✍️ Description:
5+
# This workflow is used to keep the project up to date with the latest version of the template.
6+
7+
# 🚨 GITHUB SECRETS REQUIRED:
8+
# - UPDATE_FROM_TEMPLATE_PAT: A fine-grained Personal Access Token.
9+
# This token is used to commit and push to the project repository.
10+
# You can generate one from here: https://github.com/settings/tokens?type=beta
11+
# Set the Repository access to "Only select repositories" and select the project repository.
12+
# Set the following Repo permissions:
13+
# - Contents: Read & write (to commit and push the update branch to the project repository)
14+
# - Metadata: Read-only (mandatory by GitHub)
15+
# - Workflows: Read and write (to create, update and delete workflows in the project repository)
16+
# Make sure to add it to the repo secrets with the name UPDATE_FROM_TEMPLATE_PAT:
17+
# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
18+
# - Name: UPDATE_FROM_TEMPLATE_PAT
19+
# - Value: The Personal Access Token you created
20+
21+
# ℹ️ Environment variables:
22+
# - TEMPLATE_REPOSITORY: Repository to sync with
23+
# - DIFF_EXCLUDED_ROUTES: List of files or directories to exclude from the diff.
24+
# Any changes in these files or directories will be ignored
25+
# and won't be incorporated to the Pull Request.
26+
27+
name: 🔄 Sync with template
28+
29+
on:
30+
schedule:
31+
- cron: '0 12 * * 1-5' # At 12:00 UTC on every day-of-week from Monday through Friday
32+
workflow_dispatch:
33+
inputs:
34+
template-version:
35+
type: string
36+
description: 'Template release version to sync with (e.g. v1.0.0). Leave empty to sync with the latest release.'
37+
required: false
38+
default: ''
39+
40+
env:
41+
TEMPLATE_REPOSITORY: rootstrap/react-native-template
42+
DIFF_EXCLUDED_ROUTES: |
43+
cli
44+
docs
45+
ios
46+
android
47+
.github/workflows/deploy-docs.yml
48+
.github/workflows/new-template-version.yml
49+
.github/workflows/upstream-to-pr.yml
50+
.github/workflows/sync-with-upstream.yml
51+
README-project.md
52+
53+
jobs:
54+
sync:
55+
runs-on: ubuntu-latest
56+
permissions:
57+
actions: write
58+
contents: read
59+
pull-requests: write
60+
61+
steps:
62+
- name: Check if Personal Access Token exists
63+
env:
64+
PAT: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
65+
if: env.PAT == ''
66+
run: |
67+
echo "UPDATE_FROM_TEMPLATE_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file."
68+
exit 1
69+
- name: Checkout project repository
70+
uses: actions/checkout@v3
71+
with:
72+
fetch-depth: 0
73+
path: project
74+
token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
75+
- name: Get template version used in project from package.json
76+
run: |
77+
echo "PROJECT_TEMPLATE_VERSION=v$(jq -r 'if has("rsMetadata") then .rsMetadata.templateVersion else .osMetadata.initVersion end' project/package.json | sed 's/^.*@//')" >> $GITHUB_ENV
78+
- name: Set template version to sync with
79+
run: |
80+
if [ -z "${{ inputs.template-version }}" ]; then
81+
TEMPLATE_UPDATE_VERSION=$(curl -s https://api.github.com/repos/${{ env.TEMPLATE_REPOSITORY }}/releases/latest | jq '.tag_name' | sed 's/\"//g')
82+
else
83+
TEMPLATE_UPDATE_VERSION=${{ inputs.template-version }}
84+
fi
85+
echo "TEMPLATE_UPDATE_VERSION=$TEMPLATE_UPDATE_VERSION" >> $GITHUB_ENV
86+
- name: Check if the project is up to date
87+
run: |
88+
if [[ $TEMPLATE_UPDATE_VERSION == $PROJECT_TEMPLATE_VERSION ]]; then
89+
echo "Template is up to date"
90+
cd project
91+
gh run cancel ${{ github.run_id }}
92+
gh run watch ${{ github.run_id }}
93+
fi
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
- name: Check if branch already exists
97+
run: |
98+
cd project
99+
git fetch origin
100+
BRANCH_NAME=update-template-${{ env.TEMPLATE_UPDATE_VERSION }}
101+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
102+
git branch -r | grep -q "origin/$BRANCH_NAME" && echo "BRANCH_EXISTS=true" >> $GITHUB_ENV || echo "BRANCH_EXISTS=false" >> $GITHUB_ENV
103+
- name: Check if PR already exists
104+
run: |
105+
cd project
106+
prs=$(gh pr list \
107+
--head "$BRANCH_NAME" \
108+
--json title \
109+
--jq 'length')
110+
if ((prs > 0)); then
111+
echo "PR_EXISTS=true" >> $GITHUB_ENV
112+
else
113+
echo "PR_EXISTS=false" >> $GITHUB_ENV
114+
fi
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
- name: Install dependencies
118+
if: ${{ env.BRANCH_EXISTS == 'false' }}
119+
run: |
120+
sudo apt install wiggle
121+
- name: Checkout update release of template
122+
if: ${{ env.BRANCH_EXISTS == 'false' }}
123+
uses: actions/checkout@v3
124+
with:
125+
repository: ${{ env.TEMPLATE_REPOSITORY }}
126+
ref: ${{ env.TEMPLATE_UPDATE_VERSION }}
127+
fetch-depth: 0
128+
path: react-native-template
129+
- name: Get diff between latest release and used release
130+
if: ${{ env.BRANCH_EXISTS == 'false' }}
131+
run: |
132+
EXCLUDED_ROUTES=""
133+
for route in $DIFF_EXCLUDED_ROUTES; do
134+
EXCLUDED_ROUTES="$EXCLUDED_ROUTES ':(exclude)$route'"
135+
done
136+
cd react-native-template
137+
git diff ${{ env.PROJECT_TEMPLATE_VERSION }} -- . $(echo $EXCLUDED_ROUTES | xargs) > ../update.patch
138+
- name: Update template version in package.json
139+
if: ${{ env.BRANCH_EXISTS == 'false' }}
140+
run: |
141+
cd project
142+
jq 'del(.osMetadata)' package.json > tmp.json && mv tmp.json package.json
143+
PLAIN_VERSION=${TEMPLATE_UPDATE_VERSION#v}
144+
jq --arg version $PLAIN_VERSION '.rsMetadata.templateVersion = $version' package.json > tmp.json && mv tmp.json package.json
145+
- name: Apply diff to project repository
146+
if: ${{ env.BRANCH_EXISTS == 'false' }}
147+
run: |
148+
cd project
149+
git apply --reject ../update.patch
150+
continue-on-error: true
151+
- name: Solve conflicts with wiggle
152+
if: ${{ env.BRANCH_EXISTS == 'false' }}
153+
run: |
154+
cd project
155+
find . -iname '*.rej' -exec sh -c 'printf "%s\n" "${0%.*}"' {} ';' | xargs -I _ wiggle --replace --merge _ _.rej
156+
continue-on-error: true
157+
- name: Remove wiggle's backup and .rej files
158+
if: ${{ env.BRANCH_EXISTS == 'false' }}
159+
run: |
160+
cd project
161+
find . -not -path './.git/*' -type f -name '*.porig' -delete
162+
find . -not -path './.git/*' -type f -name '*.rej' -delete
163+
- name: Commit and push changes to the update branch
164+
if: ${{ env.BRANCH_EXISTS == 'false' }}
165+
run: |
166+
cd project
167+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
168+
git config --global user.name "github-actions[bot]"
169+
git checkout -b ${{ env.BRANCH_NAME }}
170+
git add .
171+
git commit -m "chore: update template to ${{ env.TEMPLATE_UPDATE_VERSION }}"
172+
git push origin ${{ env.BRANCH_NAME }}
173+
echo "BRANCH_EXISTS=true" >> $GITHUB_ENV
174+
- name: 🎉 Create PR with changes
175+
if: ${{ env.BRANCH_EXISTS == 'true' && env.PR_EXISTS == 'false' }}
176+
run: |
177+
cd project
178+
gh pr create --title "chore: update template to ${{ env.TEMPLATE_UPDATE_VERSION }}" --body "Integrating latest changes from [rootstrap/react-native-template@${{ env.TEMPLATE_UPDATE_VERSION }}](https://github.com/rootstrap/react-native-template/releases/tag/${{ env.TEMPLATE_UPDATE_VERSION }})" --head ${{ env.BRANCH_NAME }}
179+
env:
180+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 🔗 Links:
2+
# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/check-merge-conflicts.yml
3+
4+
# ✍️ Description:
5+
# This action is used to check for merge conflicts.
6+
# Runs on any pull request, and also when pushing to main/master
7+
8+
# 🚨 GITHUB SECRETS REQUIRED: NONE
9+
10+
name: Check for merge conflicts
11+
12+
on:
13+
push:
14+
branches: [main, master]
15+
pull_request:
16+
types: [opened, synchronize]
17+
18+
jobs:
19+
check-conflicts:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: 📦 Checkout project repo
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
- name: Check for merge conflicts
27+
uses: olivernybroe/[email protected]

.github/workflows/new-template-version.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515
#
1616

1717
# 🚨 GITHUB SECRETS REQUIRED:
18-
# - GH_TOKEN: A GitHub token with write repo access.
19-
# You can generate one from here: https://github.com/settings/tokens
20-
# make sure to add it to the repo secrets with the name GH_TOKEN
21-
# Attention: Not to be confused with the GITHUB_TOKEN, this is a different token with different permissions.
18+
# - NEW_TEMPLATE_VERSION_PAT: A fine-grained Personal Access Token.
19+
# This token is used to commit, push and create a new release in the template repository.
20+
# You can generate one from here: https://github.com/settings/tokens?type=beta
21+
# Set the Repository access to "Only select repositories" and select the template repository.
22+
# Set the following Repo permissions:
23+
# - Contents: Read & write (to commit, push and create a new release)
24+
# - Metadata: Read-only (mandatory by GitHub)
25+
# - Actions: Read and write (to allow triggering other workflows, like docs deployment)
26+
# Make sure to add it to the repo secrets with the name NEW_TEMPLATE_VERSION_PAT:
27+
# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
28+
# - Name: NEW_TEMPLATE_VERSION_PAT
29+
# - Value: The Personal Access Token you created
2230

2331
name: New Template Version
2432

@@ -45,17 +53,18 @@ jobs:
4553
permissions:
4654
contents: write
4755
steps:
48-
- name: 🔍 GH_TOKEN
49-
if: env.GH_TOKEN == ''
56+
- name: Check if Personal Access Token exists
5057
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV
58+
PAT: ${{ secrets.NEW_TEMPLATE_VERSION_PAT }}
59+
if: env.PAT == ''
60+
run: |
61+
echo "NEW_TEMPLATE_VERSION_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file."
62+
exit 1
5363
- name: 📦 Checkout project repo
5464
uses: actions/checkout@v3
5565
with:
5666
fetch-depth: 0
57-
token: ${{ secrets.GH_TOKEN }}
58-
67+
token: ${{ secrets.NEW_TEMPLATE_VERSION_PAT }}
5968
- name: 📝 Git User Setup
6069
run: |
6170
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
@@ -78,3 +87,4 @@ jobs:
7887
tag: v${{ env.NEW_VERSION }}
7988
generateReleaseNotes: true
8089
draft: false
90+
token: ${{ secrets.NEW_TEMPLATE_VERSION_PAT }}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# 🔗 Links:
2+
# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/sync-with-upstream.yml
3+
4+
# ✍️ Description:
5+
# This workflow is used to keep the template up to date with the another version of the upstream repository.
6+
7+
# 🚨 GITHUB SECRETS REQUIRED:
8+
# - UPDATE_FROM_UPSTREAM_PAT: A fine-grained Personal Access Token.
9+
# This token is used to commit and push to the template repository.
10+
# You can generate one from here: https://github.com/settings/tokens?type=beta
11+
# Set the Repository access to "Only select repositories" and select the template repository.
12+
# Set the following Repo permissions:
13+
# - Contents: Read & write (to commit and push the update branch to the template repository)
14+
# - Metadata: Read-only (mandatory by GitHub)
15+
# - Workflows: Read and write (to create, update and delete workflows in the template repository)
16+
# Make sure to add it to the repo secrets with the name UPDATE_FROM_UPSTREAM_PAT:
17+
# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
18+
# - Name: UPDATE_FROM_UPSTREAM_PAT
19+
# - Value: The Personal Access Token you created
20+
21+
# ℹ️ Environment variables:
22+
# - UPSTREAM_REPOSITORY: Repository to sync with
23+
# - DIFF_EXCLUDED_ROUTES: List of files or directories to exclude from the diff.
24+
# Any changes in these files or directories will be ignored
25+
# and won't be incorporated to the Pull Request.
26+
27+
name: 🔄 Sync with upstream
28+
29+
on:
30+
schedule:
31+
- cron: '0 12 * * 1-5' # At 12:00 UTC on every day-of-week from Monday through Friday
32+
workflow_dispatch:
33+
inputs:
34+
upstream-version:
35+
type: string
36+
description: 'Upstream release version to sync with (e.g. v1.0.0). Leave empty to sync with the latest release.'
37+
required: false
38+
default: ''
39+
40+
env:
41+
UPSTREAM_REPOSITORY: obytes/react-native-template-obytes
42+
DIFF_EXCLUDED_ROUTES: |
43+
ios
44+
android
45+
46+
jobs:
47+
sync:
48+
runs-on: ubuntu-latest
49+
permissions:
50+
actions: write
51+
contents: read
52+
pull-requests: write
53+
54+
steps:
55+
- name: Check if Personal Access Token exists
56+
env:
57+
PAT: ${{ secrets.UPDATE_FROM_UPSTREAM_PAT }}
58+
if: env.PAT == ''
59+
run: |
60+
echo "UPDATE_FROM_UPSTREAM_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file."
61+
exit 1
62+
- name: Checkout template repository
63+
uses: actions/checkout@v3
64+
with:
65+
fetch-depth: 0
66+
token: ${{ secrets.UPDATE_FROM_UPSTREAM_PAT }}
67+
- name: Set upstream version to sync with
68+
run: |
69+
if [ -z "${{ inputs.upstream-version }}" ]; then
70+
UPSTREAM_UPDATE_VERSION=$(curl -s https://api.github.com/repos/${{ env.UPSTREAM_REPOSITORY }}/releases/latest | jq '.tag_name' | sed 's/\"//g')
71+
else
72+
UPSTREAM_UPDATE_VERSION=${{ inputs.upstream-version }}
73+
fi
74+
echo "UPSTREAM_UPDATE_VERSION=$UPSTREAM_UPDATE_VERSION" >> $GITHUB_ENV
75+
- name: Check if branch already exists
76+
run: |
77+
git fetch origin
78+
BRANCH_NAME=update-upstream-${{ env.UPSTREAM_UPDATE_VERSION }}
79+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
80+
git branch -r | grep -q "origin/$BRANCH_NAME" && echo "BRANCH_EXISTS=true" >> $GITHUB_ENV || echo "BRANCH_EXISTS=false" >> $GITHUB_ENV
81+
- name: Check if PR already exists
82+
run: |
83+
prs=$(gh pr list \
84+
--head "$BRANCH_NAME" \
85+
--json title \
86+
--jq 'length')
87+
if ((prs > 0)); then
88+
echo "PR_EXISTS=true" >> $GITHUB_ENV
89+
else
90+
echo "PR_EXISTS=false" >> $GITHUB_ENV
91+
fi
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
- name: Checkout update release of upstream
95+
if: ${{ env.BRANCH_EXISTS == 'false' }}
96+
run: |
97+
git remote add upstream https://github.com/${{ env.UPSTREAM_REPOSITORY }}.git
98+
git fetch upstream $UPSTREAM_UPDATE_VERSION
99+
- name: Merge latest release of upstream
100+
if: ${{ env.BRANCH_EXISTS == 'false' }}
101+
run: |
102+
UPSTREAM_UPDATE_VERSION_HASH=$(git rev-parse --short FETCH_HEAD)
103+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
104+
git config --global user.name "github-actions[bot]"
105+
git merge $UPSTREAM_UPDATE_VERSION_HASH
106+
continue-on-error: true
107+
- name: Remove excluded files from the merge
108+
if: ${{ env.BRANCH_EXISTS == 'false' }}
109+
run: |
110+
for route in $DIFF_EXCLUDED_ROUTES; do
111+
git reset -- $route
112+
done
113+
- name: Commit and push changes to the update branch
114+
if: ${{ env.BRANCH_EXISTS == 'false' }}
115+
run: |
116+
git add .
117+
git commit -m "chore: update upstream to ${{ env.UPSTREAM_UPDATE_VERSION }}"
118+
git checkout -b ${{ env.BRANCH_NAME }}
119+
git push origin ${{ env.BRANCH_NAME }}
120+
git remote rm upstream
121+
echo "BRANCH_EXISTS=true" >> $GITHUB_ENV
122+
- name: 🎉 Create PR with changes
123+
if: ${{ env.BRANCH_EXISTS == 'true' && env.PR_EXISTS == 'false' }}
124+
run: |
125+
gh pr create --title "chore: update upstream to ${{ env.UPSTREAM_UPDATE_VERSION }}" --body "Integrating latest changes from [obytes/react-native-template-obytes@${{ env.UPSTREAM_UPDATE_VERSION }}](https://github.com/obytes/react-native-template-obytes/releases/tag/${{ env.UPSTREAM_UPDATE_VERSION }})" --head ${{ env.BRANCH_NAME }}
126+
env:
127+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)