Skip to content

Commit 4435751

Browse files
author
Petr Konecny
committed
chore: map environments
1 parent fd5d585 commit 4435751

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Map Environment
2+
description: 'Maps environment names to Expo environment names'
3+
inputs:
4+
environment:
5+
required: true
6+
description: 'The environment to map (dev, staging) or pass through (development, preview, production)'
7+
outputs:
8+
expo_environment:
9+
description: 'The mapped Expo environment name (development, preview, production)'
10+
value: ${{ steps.map-env.outputs.expo_environment }}
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Map environment to Expo environment
15+
id: map-env
16+
shell: bash
17+
run: |
18+
case "${{ inputs.environment }}" in
19+
"dev")
20+
echo "expo_environment=development" >> $GITHUB_OUTPUT
21+
;;
22+
"staging")
23+
echo "expo_environment=preview" >> $GITHUB_OUTPUT
24+
;;
25+
"development"|"preview"|"production")
26+
echo "expo_environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT
27+
;;
28+
*)
29+
echo "Unknown environment: ${{ inputs.environment }}"
30+
exit 1
31+
;;
32+
esac

.github/actions/ota-update/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ inputs:
77
version:
88
required: true
99
description: 'The version number'
10+
environment:
11+
required: true
12+
description: 'The environment to update'
1013
runs:
1114
using: composite
1215
steps:
1316
- name: Set environment variables
1417
shell: bash
1518
run: |
1619
echo "EXPO_PUBLIC_APP_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
20+
21+
- name: Map environment
22+
uses: ./.github/actions/map-environment
23+
id: map-env
24+
with:
25+
environment: ${{ inputs.environment }}
26+
1727
- name: Perform OTA Update
1828
shell: bash
1929
run: |
2030
eas update --channel ${{ inputs.channel }} \
31+
--environment ${{ steps.map-env.outputs.expo_environment }} \
2132
--message "Update ${{ inputs.channel }} to ${{ inputs.version }}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ web-build/
1515

1616
# env
1717
.env
18+
.env.local
1819

1920
# native folers
2021
android/

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,30 @@ To replicate Figma design consistently on majority of mobile screen sizes, we sh
193193
194194
## Adding new `ENV` variables:
195195

196-
**Format**:
196+
We highly recommend using EAS to manage environments.
197197

198-
- All variables must use the `EXPO_PUBLIC` prefix! e.g., `EXPO_PUBLIC_API_URL`
198+
We map our environment names to the Expo environments names.
199199

200-
**Github**:
200+
```
201+
"dev": "development",
202+
"staging": "preview",
203+
"production": "production"
204+
```
201205

202-
- There are two options for adding/managing env credentials:
206+
Inside Github Actions we use an action to map the environments automatically.
207+
To add new environment variable:
203208

204-
1. **Variables by a specific env**:
209+
- Either add it through the Expo dashboard
210+
- Or through eas cli:
205211

206-
> Settings -> Environments -> Select/add Env (dev, staging, production) -> Add a new variable
212+
```
213+
eas env:create [EXPO_ENVIRONMENT] --name <name> --value <value>
214+
```
207215

208-
2. **Shared variables**:
216+
> ⚠️ All variables must use the `EXPO_PUBLIC` prefix! e.g., `EXPO_PUBLIC_API_URL`
209217
210-
> Settings -> Secrets and Variables -> Actions -> Select Variables tab -> New repository variable
218+
You can also pull variables from EAS to your local `.env` file:
211219

212220
```
213-
221+
eas env:pull [EXPO_ENVIRONMENT]
214222
```

eas.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{
22
"cli": {
3-
"version": ">= 3.13.3"
3+
"version": ">= 3.13.3",
4+
"appVersionSource": "remote"
45
},
56
"build": {
67
"base": {
78
"ios": {
89
"resourceClass": "medium"
910
}
1011
},
11-
"cli": {
12-
"appVersionSource": "remote"
13-
},
1412
"dev": {
1513
"extends": "base",
1614
"developmentClient": true,
1715
"distribution": "internal",
16+
"environment": "development",
1817
"android": {
1918
"buildType": "apk"
2019
},
@@ -25,6 +24,7 @@
2524
},
2625
"dev-sim": {
2726
"extends": "dev",
27+
"environment": "development",
2828
"ios": {
2929
"simulator": true
3030
}
@@ -34,6 +34,7 @@
3434
"distribution": "store",
3535
"channel": "staging",
3636
"autoIncrement": true,
37+
"environment": "preview",
3738
"env": {
3839
"EXPO_PUBLIC_APP_ENV": "staging"
3940
}
@@ -42,6 +43,7 @@
4243
"extends": "base",
4344
"distribution": "store",
4445
"channel": "production",
46+
"environment": "production",
4547
"env": {
4648
"EXPO_PUBLIC_APP_ENV": "production"
4749
}

0 commit comments

Comments
 (0)