1
+ name : Expo QR Code Preview
2
+
3
+ on :
4
+ pull_request :
5
+ types : [opened, synchronize]
6
+
7
+ jobs :
8
+ preview :
9
+ runs-on : ubuntu-latest
10
+ permissions :
11
+ pull-requests : write
12
+
13
+ steps :
14
+ - name : 🏗 Setup repo
15
+ uses : actions/checkout@v4
16
+ with :
17
+ token : ${{ secrets.GH_PAT }}
18
+
19
+ - name : 🏗 Setup Node
20
+ uses : actions/setup-node@v4
21
+ with :
22
+ node-version : 22.x
23
+
24
+ - name : 📦 Install dependencies
25
+ run : npm install
26
+
27
+ - name : 🏗 Setup EAS
28
+ uses : expo/expo-github-action@v8
29
+ with :
30
+ eas-version : latest
31
+ token : ${{ secrets.EXPO_TOKEN }}
32
+
33
+ - name : 🚀 Create preview and extract details
34
+ id : create-preview
35
+ run : |
36
+ OUTPUT=$(eas update --auto --branch ${{ github.event.pull_request.head.ref }})
37
+ echo "$OUTPUT"
38
+
39
+ # Extract the Update Group ID (groupId)
40
+ GROUP_ID=$(echo "$OUTPUT" | grep -oP 'Update group ID\s+\K[\w-]+')
41
+
42
+ # Extract the EAS Dashboard URL
43
+ EAS_DASHBOARD_URL=$(echo "$OUTPUT" | grep -oP 'EAS Dashboard\s+\Khttps://expo.dev/accounts/[^ ]+')
44
+
45
+ # Parse the account name and project slug dynamically
46
+ ACCOUNT_NAME=$(echo "$EAS_DASHBOARD_URL" | awk -F'/' '{print $(NF-3)}')
47
+ PROJECT_SLUG=$(echo "$EAS_DASHBOARD_URL" | awk -F'/' '{print $(NF-1)}')
48
+
49
+ # Fetch the correct appId using `eas project:info`
50
+ echo "Fetching EAS Project Info..."
51
+ PROJECT_INFO=$(eas project:info)
52
+ echo "EAS Project Info Output: $PROJECT_INFO"
53
+
54
+ # Extract appId using grep instead of jq
55
+ APP_ID=$(echo "$PROJECT_INFO" | grep -oP 'ID\s+\K[\w-]+')
56
+
57
+ # Extract the last update timestamp (from commit timestamp)
58
+ COMMIT_TIMESTAMP=$(echo "$OUTPUT" | grep -oP 'Commit\s+\K[\w\d]+')
59
+
60
+ # Convert timestamp to readable UTC format
61
+ LAST_UPDATED=$(date -u -d "@$(git show -s --format=%ct $COMMIT_TIMESTAMP)" "+%b %-d, %Y %-I:%M%p UTC")
62
+
63
+ if [ -z "$APP_ID" ] || [ -z "$GROUP_ID" ] || [ -z "$ACCOUNT_NAME" ] || [ -z "$PROJECT_SLUG" ] || [ -z "$LAST_UPDATED" ]; then
64
+ echo "❌ Failed to extract required values."
65
+ exit 1
66
+ fi
67
+
68
+ DEEP_LINK="exp+://expo-development-client/?url=https://u.expo.dev/$APP_ID/group/$GROUP_ID"
69
+ UPDATE_LINK="https://expo.dev/accounts/$ACCOUNT_NAME/projects/$PROJECT_SLUG/updates/$GROUP_ID"
70
+ QR_CODE_URL="https://qr.expo.dev/eas-update?slug=exp&projectId=$APP_ID&groupId=$GROUP_ID&host=u.expo.dev&scale=2"
71
+
72
+ echo "Deep Link: $DEEP_LINK"
73
+ echo "UPDATE_LINK=$UPDATE_LINK" >> $GITHUB_ENV
74
+ echo "QR_CODE_URL=$QR_CODE_URL" >> $GITHUB_ENV
75
+ echo "LAST_UPDATED=$LAST_UPDATED" >> $GITHUB_ENV
76
+
77
+ - name : 📢 Update or Post Expo QR Code in PR
78
+ if : success()
79
+ uses : actions/github-script@v7
80
+ with :
81
+ github-token : ${{ secrets.GITHUB_TOKEN }}
82
+ script : |
83
+ const updateLink = process.env.UPDATE_LINK;
84
+ const qrCodeUrl = process.env.QR_CODE_URL;
85
+ const lastUpdated = process.env.LAST_UPDATED;
86
+
87
+ if (!updateLink || !qrCodeUrl || !lastUpdated) {
88
+ console.error("Missing update link, QR code URL, or last updated timestamp.");
89
+ return;
90
+ }
91
+
92
+ const { owner, repo, number } = context.issue;
93
+ const commentIdentifier = "🚀 **Expo Preview Ready!**"; // Unique identifier
94
+
95
+ // Generate comment body with QR Code
96
+ const commentBody = `
97
+ 🚀 **Expo Preview Ready!** — *Updated: ${lastUpdated}*
98
+
99
+ 📱 Scan the QR code below to test on **Expo Dev Client**:
100
+
101
+ 
102
+
103
+ <a href="${updateLink}" target="_blank"><strong>Open Expo Update ↗︎</strong></a>
104
+
105
+ ---
106
+
107
+ 🎩 *Made by [Torii Studio](https://torii.studio)*
108
+ `;
109
+
110
+ // Fetch existing comments
111
+ const comments = await github.rest.issues.listComments({
112
+ owner,
113
+ repo,
114
+ issue_number: number
115
+ });
116
+
117
+ const existingComment = comments.data.find(comment =>
118
+ comment.body.includes(commentIdentifier)
119
+ );
120
+
121
+ if (existingComment) {
122
+ // Update the existing comment
123
+ await github.rest.issues.updateComment({
124
+ owner,
125
+ repo,
126
+ comment_id: existingComment.id,
127
+ body: commentBody
128
+ });
129
+ console.info("✅ Updated existing Expo preview comment.");
130
+ } else {
131
+ // Create a new comment
132
+ await github.rest.issues.createComment({
133
+ owner,
134
+ repo,
135
+ issue_number: number,
136
+ body: commentBody
137
+ });
138
+ console.info("✅ Created new Expo preview comment.");
139
+ }
0 commit comments