forked from protomaps/PMTiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Update protomaps tiles on Cloudflare R2 | ||
|
||
on: | ||
schedule: | ||
- cron: '15 14 1 */2 *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-tiles: | ||
runs-on: | ||
labels: 8core-ubuntu | ||
|
||
steps: | ||
- name: Set AWS credentials | ||
env: | ||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | ||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | ||
run: | | ||
echo "Setting AWS Credentials" | ||
aws configure set aws_access_key_id "$R2_ACCESS_KEY_ID" | ||
aws configure set aws_secret_access_key "$R2_SECRET_ACCESS_KEY" | ||
- name: Download latest tileset | ||
run: | | ||
TODAY="$(date +'%Y%m%d')" | ||
echo "TODAY=$TODAY" >> $GITHUB_ENV | ||
echo "Today's date for filename is $TODAY" | ||
echo "Downloading protomaps pmtiles file." | ||
## wget https://build.protomaps.com/${TODAY}.pmtiles | ||
echo "test" > 20231112.pmtiles | ||
- name: Upload tileset to Cloudflare R2 | ||
env: | ||
R2_API_ENDPOINT: ${{ secrets.R2_API_ENDPOINT }} | ||
run: | | ||
aws s3api list-objects-v2 --bucket protomaps --endpoint-url https://"$R2_API_ENDPOINT".r2.cloudflarestorage.com > output.json | ||
OLD_MAP_TILES=$(jq -r '.Contents[0].Key') | ||
echo "OLD_MAP_TILES=$OLD_MAP_TILES" >> $GITHUB_ENV | ||
echo "Uploading file to Cloudflare R2" | ||
aws s3 cp "${{ env.TODAY }}".pmtiles s3://protomaps/"${{ env.TODAY }}"/world.pmtiles --endpoint-url https://"$R2_API_ENDPOINT".r2.cloudflarestorage.com | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
js | ||
serverless/cloudflare | ||
sparse-checkout-cone-mode: false | ||
|
||
- name: Update PMTILES_PATH environment variable in wrangler.toml | ||
run: | | ||
PMTILES_PATH="${{ env.TODAY }}/{name}.pmtiles" | ||
sed -i -E 's|PMTILES_PATH =.*|PMTILES_PATH = "'"$PMTILES_PATH"'"|g' serverless/cloudflare/wrangler.toml | ||
- name: Build & Deploy Worker | ||
uses: cloudflare/wrangler-action@v3 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }} | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
preCommands: | | ||
cd js | ||
npm install | ||
cd ../serverless/cloudflare | ||
npm install | ||
- name: Push updated wrangler.toml to repo | ||
uses: test-room-7/action-update-file@v1 | ||
with: | ||
file-path: serverless/cloudflare/wrangler.toml | ||
commit-msg: Update wrangler.toml to latest version | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Delete old map tiles file from Cloudflare R2 | ||
run: | | ||
aws s3 rm s3://protomaps/"${{ env.OLD_MAP_FILE }}" --endpoint-url https://"$R2_API_ENDPOINT".r2.cloudflarestorage.com |