nfp_sites/.forgejo/workflows/deploy.yaml

79 lines
3 KiB
YAML
Raw Permalink Normal View History

2023-11-05 06:24:01 +00:00
on:
push:
branches:
- master
jobs:
deploy:
2024-11-21 12:40:12 +00:00
runs-on: arch
2023-11-05 06:24:01 +00:00
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Check for new release
run: |
chmod +x ./7zas
echo ""
echo "Checking following projects:"
for f in *; do
[ -d "$f" ] && [ ! -L "$f" ] && [ ! "$f" = "base" ] && echo " * $f";
done
echo ""
for f in *; do
[ ! -d "$f" ] || [ -L "$f" ] || [ "$f" = "base" ] && continue;
echo ""
echo "------------------------------------"
echo ""
echo "checking $f";
cd $f
CURR_VER="$(cat package.json | jq -r .name)_v$(cat package.json | jq -r .version)"
CURR_NAME="$(cat package.json | jq -r .name) v$(cat package.json | jq -r .version)"
2024-11-21 12:40:12 +00:00
echo "Checking https://git.nfp.is/api/v1/repos/${{ github.repository }}/releases for name ${CURR_NAME}"
2023-11-05 06:24:01 +00:00
2024-11-21 12:40:12 +00:00
if curl -s -X GET -H "Authorization: token ${{ secrets.deploytoken }}" https://git.nfp.is/api/v1/repos/${{ github.repository }}/releases | grep -o "\"name\"\:\"${CURR_NAME}\"" > /dev/null; then
echo "Skipping ${{ github.job }} since $CURR_NAME already exists";
2023-11-05 06:24:01 +00:00
cd ..
continue;
fi
echo "New release ${CURR_VER} found, running npm install..."
mv package.json fuck-you-npm-package.json
mv build-package.json package.json
npm install && npm run build
mv package.json build-package.json
mv fuck-you-npm-package.json package.json
../7zas a -xr!*.xcf -mx9 "${CURR_VER}_build-sc.7z" package.json index.mjs api base public
echo "Creating ${CURR_VER} release on gitea"
RELEASE_RESULT=$(curl \
-X POST \
-H "Authorization: token ${{ secrets.deploytoken }}" \
-H "Content-Type: application/json" \
2024-11-21 12:40:12 +00:00
https://git.nfp.is/api/v1/repos/${{ github.repository }}/releases \
-d "{\"tag_name\":\"${CURR_VER}\",\"name\":\"${CURR_NAME}\",\"body\":\"Automatic release from Appveyor from ${{ github.sha }} :\n\n${{ github.event.head_commit.message }}\"}")
2023-11-05 06:24:01 +00:00
RELEASE_ID=$(echo $RELEASE_RESULT | jq -r .id)
echo "Adding ${CURR_VER}_build-sc.7z to release ${RELEASE_ID}"
curl \
-X POST \
-H "Authorization: token ${{ secrets.deploytoken }}" \
-F "attachment=@${CURR_VER}_build-sc.7z" \
2024-11-21 12:40:12 +00:00
https://git.nfp.is/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets
2023-11-05 06:24:01 +00:00
MAN_PORT=$(cat package.json | jq -r .port)
MAN_NAME=$(cat package.json | jq -r .name)
echo "Deplying to production"
2024-11-21 12:40:12 +00:00
echo "curl -X POST http://192.168.93.52:$MAN_PORT/update/$MAN_NAME"
curl -X POST http://192.168.93.52:$MAN_PORT/update/$MAN_NAME
2023-11-05 06:25:29 +00:00
cd ..
2023-11-05 06:24:01 +00:00
done