Skip to content

Commit b6863c6

Browse files
mmathieumCopilot
andauthored
Use GH secrets for Maps JS API key (#25)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 66c071f commit b6863c6

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,19 @@ jobs:
3232
- name: Checkout
3333
uses: actions/checkout@v4
3434

35-
# TODO: Inject the API Key secret into the source file
36-
# - name: Inject API Key
37-
# run: |
38-
# sed -i 's/REPLACE_WITH_MY_API_KEY/${{ secrets.MY_API_KEY }}/g' main.js
35+
# Inject the API Key secret into the source file
36+
- name: Inject API Key
37+
env:
38+
MT_MAPS_JS_API_KEY: ${{ secrets.MT_MAPS_JS_API_KEY }}
39+
run: |
40+
set -euo pipefail
41+
if [ -z "${MT_MAPS_JS_API_KEY}" ]; then
42+
echo "MT_MAPS_JS_API_KEY is not set" >&2
43+
exit 1
44+
fi
45+
esc_key=$(printf '%s' "$MT_MAPS_JS_API_KEY" | sed -e 's/[\\/&]/\\\\&/g')
46+
sed -i "s/MT_REPLACE_WITH_MAPS_JS_API_KEY/${esc_key}/g" ./index.html
47+
sed -i "s/MT_REPLACE_WITH_MAPS_JS_API_KEY/${esc_key}/g" ./dev/map/empty.html
3948
4049
4150
- name: Setup Pages

dev/map/empty.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</style>
1818

1919
<!-- This APK key is restricted to 'Maps JavaScript API' on 'mtransitapps.github.io' website: -->
20-
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCrAHs1Dp4dgQxA0-17PJqaCfK_Jpg85Hs&libraries=maps"></script>
20+
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MT_REPLACE_WITH_MAPS_JS_API_KEY&libraries=maps"></script>
2121
<!-- Use demo key for local testing: https://developers.google.com/maps/documentation/javascript/demo-key -->
2222
<!-- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=INSERT_DEMO_KEY_HERE&libraries=maps"></script> -->
2323

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</style>
9191

9292
<!-- This APK key is restricted to 'Maps JavaScript API' on 'mtransitapps.github.io' website: -->
93-
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCrAHs1Dp4dgQxA0-17PJqaCfK_Jpg85Hs&libraries=maps,marker"></script>
93+
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MT_REPLACE_WITH_MAPS_JS_API_KEY&libraries=maps,marker"></script>
9494
<!-- Use demo key for local testing: https://developers.google.com/maps/documentation/javascript/demo-key -->
9595
<!-- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=INSERT_DEMO_KEY_HERE&libraries=maps,marker"></script> -->
9696

0 commit comments

Comments
 (0)