Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hostUrl in manifest file during build #306

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/src/generated/
webpack.config.js
17 changes: 17 additions & 0 deletions .github/workflows/azure-static-web-apps-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and deploy
env:
URL_PROD: "https://lively-ground-0d7c50410-${{github.event.number}}.centralus.azurestaticapps.net"

steps:
- name: Checkout
Expand All @@ -31,6 +33,7 @@ jobs:
app_location: "/"
# Built app content directory
output_location: "dist"
app_build_command: "npm run build -- --env URL_PROD=$URL_PROD"

cleanup_pull_request:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
Expand All @@ -43,3 +46,17 @@ jobs:
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: "close"

add-pr-comment:
needs: build_and_deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: mshick/add-pr-comment@v1
with:
message: |
https://lively-ground-0d7c50410-${{github.event.number}}.centralus.azurestaticapps.net/manifest.prod.xml
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
allow-repeats: false # Don't comment the same URL twice
24 changes: 24 additions & 0 deletions .github/workflows/comment-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# name: Comment Manifest Url

# on:
# push:
# branches:
# - main
# pull_request:
# types: [opened]
# branches:
# - main

# jobs:
# test:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - uses: mshick/add-pr-comment@v1
# with:
# message: |
# https://lively-ground-0d7c50410-${{github.event.number}}.centralus.azurestaticapps.net/manifest.prod.xml
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
# allow-repeats: false # Don't comment the same URL twice
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"msjsdiag.debugger-for-chrome",
"msjsdiag.debugger-for-edge",
"msoffice.microsoft-office-add-in-debugger",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
Expand Down
15 changes: 10 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
var dotenv = require("dotenv").config({ path: __dirname + "/.env" });

const urlDev = "https://localhost:3000/";
const urlProd = "https://www.contoso.com/"; // CHANGE THIS TO YOUR PRODUCTION DEPLOYMENT LOCATION

module.exports = async (env, options) => {
const dev = options.mode === "development";
const urlDev = process.env.urlDev || "https://localhost:3000";
const urlProd = env.URL_PROD || "https://www.contoso.com";
const buildType = dev ? "dev" : "prod";
const config = {
devtool: "source-map",
Expand Down Expand Up @@ -58,14 +57,20 @@ module.exports = async (env, options) => {
to: "taskpane.css",
from: "./src/taskpane/taskpane.css",
},
{
from: "./assets",
to: "assets",
},
{
to: "[name]." + buildType + ".[ext]",
from: "manifest*.xml",
transform(content) {
if (dev) {
return content;
} else {
return content.toString().replace(new RegExp(urlDev, "g"), urlProd);
return content
.toString()
.replace(new RegExp(urlDev, "g"), urlProd);
}
},
},
Expand Down Expand Up @@ -105,7 +110,7 @@ module.exports = async (env, options) => {
? options.https
: await devCerts.getHttpsServerOptions(),
port: process.env.npm_package_config_dev_server_port || 3000,
}
};
}

return config;
Expand Down