2024-12-03 16:12:57 +01:00
on :
2025-03-29 16:41:53 +01:00
workflow_dispatch :
2024-12-14 21:29:06 +01:00
push :
branches-ignore :
- build/*
pull_request :
2024-12-03 16:12:57 +01:00
jobs :
2024-12-09 22:47:42 +01:00
deploy_on_hosted :
2024-12-09 22:20:51 +01:00
runs-on : [ ubuntu-latest, hetzner-access]
2024-12-03 16:12:57 +01:00
steps :
2025-03-26 15:36:57 +01:00
- uses : https://source.mapcomplete.org/actions/checkout@v4
2024-12-03 16:12:57 +01:00
- name : Set up Node.js
2025-03-28 12:52:52 +01:00
uses : https://source.mapcomplete.org/actions/setup-node@v4
2024-12-03 16:12:57 +01:00
with :
node-version : "20"
cache : "npm"
cache-dependency-path : package-lock.json
2025-03-16 23:47:12 +01:00
2025-03-29 01:28:01 +01:00
- name : install deps
run : npm ci
shell : bash
2024-12-03 16:12:57 +01:00
- name : create generated dir
2025-03-07 21:47:26 +01:00
run : mkdir -p ./assets/generated
2024-12-03 16:12:57 +01:00
shell : bash
- name : create dependencies
run : npm run generate:licenses; npm run generate:images; npm run generate:charging-stations; npm run generate:service-worker; npm run download:editor-layer-index
shell : bash
- name : sync translations
run : npm run generate:translations
shell : bash
2024-12-09 22:45:09 +01:00
- name : Prepare build
run : npm run generate:service-worker && ./scripts/prepare-build.sh
shell : bash
- name : Run tests
2024-12-03 16:50:10 +01:00
run : |
2024-12-05 10:49:39 +01:00
# This is the same as `npm run test`, but `vitest` doesn't want to run within npm :shrug:
export NODE_OPTIONS="--max-old-space-size=8192"
npm run clean:tests
npm run generate:doctests 2>&1 | grep -v "No doctests found in"
2025-03-16 23:47:12 +01:00
vitest --run test && npm run clean:tests
2024-12-03 16:12:57 +01:00
shell : bash
2024-12-09 22:45:09 +01:00
- name : Build files
run : npm run build
2024-12-09 21:31:23 +01:00
- name : Zipping dist file
2024-12-09 22:19:07 +01:00
run : |
2025-03-29 16:41:16 +01:00
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
2025-03-31 01:22:51 +02:00
rm -rf /tmp/${BRANCH}
2025-03-30 12:50:08 +02:00
mv dist /tmp/${BRANCH}
2025-03-17 02:04:40 +01:00
cd /tmp
2025-03-30 12:50:08 +02:00
zip ${BRANCH}.zip -r ${BRANCH}/*
2025-03-17 02:04:40 +01:00
cd -
2024-12-09 21:31:23 +01:00
- name : uploading file
2025-03-29 16:41:16 +01:00
run : |
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
scp /tmp/${BRANCH}.zip hetzner:/root/staging/
2024-12-09 21:31:23 +01:00
2025-03-17 02:37:31 +01:00
- name : cleanup files
2025-03-29 16:41:16 +01:00
run : |
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
2025-03-30 13:10:01 +02:00
rm /tmp/${BRANCH}.zip && rm -rf /tmp/${BRANCH}/
2025-03-17 02:37:31 +01:00
2024-12-09 21:31:23 +01:00
- name : unzipping remote file
2025-03-29 16:41:16 +01:00
run : |
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
2025-03-31 02:43:05 +02:00
ssh hetzner "cd /root/staging && rm -rf ${BRANCH} && unzip ${BRANCH}.zip && rm -rf /root/public/${BRANCH} && mv /root/staging/${BRANCH}/ /root/public/ && date --iso > /root/public/${BRANCH}/date.txt && rm ${BRANCH}.zip"
2024-12-09 21:31:23 +01:00
2025-03-26 00:54:23 +01:00
- name : Comment on the PR
2025-03-03 01:21:06 +01:00
run : |
2025-03-29 16:41:16 +01:00
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
2025-03-26 00:54:23 +01:00
PR_NUMBER=$(echo ${{ github.event.pull_request.number || github.event.issue.number }})
if [[ -n "$PR_NUMBER" ]]
then
echo "Found a pull request or issue number, will post to $PR_NUMBER ..."
2025-03-29 16:41:16 +01:00
MSG=$(echo "Congratulations! This PR been successfully built and has been deployed. It is (temporarily) available on https://builds.mapcomplete.org/${BRANCH}")
2025-03-26 00:54:23 +01:00
BODY="{\"body\": \"$MSG\"}"
# Token must have following permissions: issue > read and write
curl -X POST "https://source.mapcomplete.org/api/v1/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
2025-03-03 01:21:06 +01:00
-H "Content-Type: application/json" \
-H "Authorization: token $FORGEJO_TOKEN" \
2025-03-26 00:54:23 +01:00
-d "$BODY"
fi
2025-03-03 01:21:06 +01:00
env :
FORGEJO_TOKEN : ${{ secrets.FORGEJO_TOKEN }}