nfp_sites/.gitea/workflows/nfp_moe.yaml

56 lines
2.5 KiB
YAML
Raw Normal View History

2023-11-04 04:00:11 +00:00
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
nfp_moe:
runs-on: alpine
steps:
2023-11-04 04:01:01 +00:00
- name: Check out repository code
uses: actions/checkout@v3
2023-11-04 04:00:11 +00:00
- name: Check for new release
2023-11-05 03:39:36 +00:00
continue-on-error: true_or_false
2023-11-04 04:00:11 +00:00
run: |
2023-11-04 04:04:37 +00:00
cd ${{ gitea.job }}
2023-11-04 04:00:11 +00:00
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)"
2023-11-05 03:31:48 +00:00
2023-11-04 04:00:11 +00:00
echo "Checking https://git.nfp.is/api/v1/repos/${{ gitea.repository }}/releases for name ${CURR_NAME}"
2023-11-05 03:39:36 +00:00
curl -s -X GET -H "Authorization: token ${{ secrets.deploytoken }}" https://git.nfp.is/api/v1/repos/${{ gitea.repository }}/releases | grep -o "\"name\"\:\"${CURR_NAME}\"" > /dev/null || { curlexit=$?; }
2023-11-04 04:00:11 +00:00
2023-11-05 03:39:36 +00:00
if [ $curlexit -eq 0 ] ; then
2023-11-04 04:00:11 +00:00
echo "Skipping ${{ gitea.job }} since $CURR_NAME already exists";
2023-11-05 03:31:48 +00:00
exit 0;
2023-11-04 04:00:11 +00:00
fi
2023-11-05 03:31:48 +00:00
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 release on gitea"
RELEASE_RESULT=$(curl \
-X POST \
-H "Authorization: token ${{ secrets.deploytoken }}" \
-H "Content-Type: application/json" \
https://git.nfp.is/api/v1/repos/${{ gitea.repository }}/releases \
-d "{\"tag_name\":\"${CURR_VER}\",\"name\":\"${CURR_NAME}\",\"body\":\"Automatic release from Appveyor from ${{ gitea.sha }} :\n\n${{ gitea.event.head_commit.message }}\"}")
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" \
https://git.nfp.is/api/v1/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets
MAN_PORT=$(cat package.json | jq -r .port)
MAN_NAME=$(cat package.json | jq -r .name)
echo "Deplying to production"
echo "curl -X POST http://192.168.93.50:$MAN_PORT/update/$MAN_NAME"
curl -X POST http://192.168.93.50:$MAN_PORT/update/$MAN_NAME