Skip to content

Commit 8e0eb37

Browse files
authored
Merge pull request #384 from csfloat/feature/staging-deployment
Add A Beta Deployment Workflow
2 parents dd5393c + c806213 commit 8e0eb37

4 files changed

Lines changed: 126 additions & 7 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Submit Staging to Chrome Web Store
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
workflow_dispatch:
7+
8+
# Ensure only one staging deployment runs at a time, canceling outdated runs
9+
concurrency:
10+
group: "staging-deploy"
11+
cancel-in-progress: true
12+
13+
jobs:
14+
deploy-staging:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node-version: [24.x]
19+
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: "npm"
28+
29+
- name: Install Dependencies
30+
run: npm ci
31+
32+
- name: Build Staging Extension
33+
run: npm run build_staging
34+
env:
35+
GITHUB_RUN_NUMBER: ${{ github.run_number }}
36+
37+
- name: Zip Staging Extension
38+
run: |
39+
cd dist
40+
zip -r ../staging-extension.zip .
41+
cd ..
42+
43+
- name: Upload Staging Artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: staging-extension-${{ github.run_number }}
47+
path: ./staging-extension.zip
48+
retention-days: 180
49+
50+
- name: Cancel Pending Review (If Exists)
51+
continue-on-error: true
52+
run: |
53+
echo "Generating access token..."
54+
ACCESS_TOKEN=$(curl -s -f -X POST "https://oauth2.googleapis.com/token" \
55+
-d "client_id=${{ secrets.OAUTH_CLIENT_ID }}" \
56+
-d "client_secret=${{ secrets.OAUTH_CLIENT_SECRET }}" \
57+
-d "refresh_token=${{ secrets.OAUTH_REFRESH_TOKEN }}" \
58+
-d "grant_type=refresh_token" | jq -r .access_token)
59+
60+
echo "Attempting to cancel any pending staging reviews..."
61+
curl -s -f -X POST \
62+
-H "Authorization: Bearer $ACCESS_TOKEN" \
63+
-H "Content-Length: 0" \
64+
"https://chromewebstore.googleapis.com/v2/publishers/${{ secrets.CWS_PUBLISHER_ID }}/items/${{ secrets.STAGING_CHROME_EXTENSION_ID }}:cancelSubmission"
65+
66+
- name: Publish to Chrome Web Store (Staging)
67+
uses: browser-actions/release-chrome-extension@v0.2.1
68+
with:
69+
extension-id: ${{ secrets.STAGING_CHROME_EXTENSION_ID }}
70+
extension-path: ./staging-extension.zip
71+
oauth-client-id: ${{ secrets.OAUTH_CLIENT_ID }}
72+
oauth-client-secret: ${{ secrets.OAUTH_CLIENT_SECRET }}
73+
oauth-refresh-token: ${{ secrets.OAUTH_REFRESH_TOKEN }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"scripts": {
1414
"build": "webpack --env mode=prod browser=chrome --config webpack.config.js --stats-error-details",
15+
"build_staging": "webpack --env mode=staging browser=chrome --config webpack.config.js --stats-error-details",
1516
"build_ff": "webpack --env mode=prod browser=firefox --config webpack.config.js --stats-error-details",
1617
"start": "webpack --env mode=development browser=chrome --config webpack.config.js --stats-error-details --watch",
1718
"start_ff": "webpack --env mode=development browser=firefox --config webpack.config.js --stats-error-details --watch",

src/environment.staging.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const environment = {
2+
csfloat_base_api_url: 'https://csfloat.build/api',
3+
notary: {
4+
tlsn: 'https://notary.csfloat.com',
5+
ws: 'wss://notary.csfloat.com/proxy',
6+
loggingLevel: 'Error',
7+
},
8+
reverse_watch_base_api_url: 'https://reverse.watch/api',
9+
};

webpack.config.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ module.exports = (env) => {
9191
test: /environment\.ts$/,
9292
loader: 'file-replace-loader',
9393
options: {
94-
condition: mode === 'development',
95-
replacement: resolve('./src/environment.dev.ts'),
94+
// Activate replacement if mode is development OR staging
95+
condition: mode === 'development' || mode === 'staging',
96+
// Dynamically route to the correct file
97+
replacement:
98+
mode === 'staging'
99+
? resolve('./src/environment.staging.ts')
100+
: resolve('./src/environment.dev.ts'),
96101
},
97102
},
98103
{
@@ -110,7 +115,7 @@ module.exports = (env) => {
110115
new CopyPlugin({
111116
patterns: [
112117
{from: 'icons', to: 'icons', context: '.'},
113-
{from: 'data', to: 'data', context: '.', globOptions: { ignore: ['bluegem.json'] } },
118+
{from: 'data', to: 'data', context: '.', globOptions: {ignore: ['bluegem.json']}},
114119
{from: 'src/global.css', to: 'src/', context: '.'},
115120
{from: 'src/background_ff.html', to: 'src/', context: '.'},
116121
{from: 'src/steamcommunity_ruleset.json', to: 'src/', context: '.'},
@@ -149,6 +154,31 @@ module.exports = (env) => {
149154
processed.externally_connectable.matches.push('http://localhost:4200/*');
150155
}
151156

157+
if (mode === 'staging') {
158+
// https://developer.chrome.com/docs/extensions/develop/migrate/publish-mv3#publish-beta
159+
// Grab the run number from the GitHub Action environment, default to 0 for local builds
160+
const runNumber = process.env.GITHUB_RUN_NUMBER || '0';
161+
162+
// Append the run number to the strict version (e.g., 5.14.0.42)
163+
processed.version = `${processed.version}.${runNumber}`;
164+
165+
// Update names
166+
processed.name += ' - STAGING';
167+
processed.short_name += ' (Staging)';
168+
processed.version_name = `${processed.version} (Staging)`;
169+
170+
if (!processed.externally_connectable.matches.includes('*://*.csfloat.build/*')) {
171+
processed.externally_connectable.matches.push('*://*.csfloat.build/*');
172+
}
173+
174+
const versionResource = processed.web_accessible_resources.find((e) =>
175+
e.resources[0].includes('version.txt')
176+
);
177+
if (versionResource && !versionResource.matches.includes('https://csfloat.build/*')) {
178+
versionResource.matches.push('https://csfloat.build/*');
179+
}
180+
}
181+
152182
if (env.browser === 'firefox') {
153183
processed = convertToFirefoxManifest(processed);
154184
}
@@ -162,17 +192,23 @@ module.exports = (env) => {
162192
transform(raw) {
163193
let processed = JSON.parse(raw.toString());
164194

195+
// Apply the exact same version bump for staging
196+
if (mode === 'staging') {
197+
const runNumber = process.env.GITHUB_RUN_NUMBER || '0';
198+
return `${processed.version}.${runNumber}`;
199+
}
200+
165201
return processed.version;
166202
},
167203
},
168204
],
169205
}),
170206
// Add Gzip compression for bluegem.json
171207
new CompressionPlugin({
172-
filename: "[path][base].gz", // Change extension to .gz
173-
algorithm: "gzip",
208+
filename: '[path][base].gz', // Change extension to .gz
209+
algorithm: 'gzip',
174210
test: /bluegem\.json$/,
175-
deleteOriginalAssets: true,
211+
deleteOriginalAssets: true,
176212
}),
177213
new webpack.ProvidePlugin({
178214
Buffer: ['buffer', 'Buffer'],
@@ -192,7 +228,7 @@ module.exports = (env) => {
192228
headers: {
193229
'Cross-Origin-Embedder-Policy': 'require-corp',
194230
'Cross-Origin-Opener-Policy': 'same-origin',
195-
}
231+
},
196232
},
197233
};
198234
};

0 commit comments

Comments
 (0)