Fetch & Deploy to gis.ee/sadamad/ #46
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
name: Fetch & Deploy to gis.ee/sadamad/ | |
on: | |
schedule: | |
- cron: "25 5 * * 1,4" | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
fetch: | |
name: Fetch | |
runs-on: ubuntu-latest | |
outputs: | |
ok: ${{ steps.check.outputs.ok }} | |
steps: | |
- name: Checkout to main | |
uses: actions/checkout@v4 | |
- name: Set up Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm ci | |
- name: Fetch files | |
run: npm run start | |
- name: Upload fetched files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ports-files | |
path: ./public | |
- name: Check git status | |
id: check | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "ok=1" >> $GITHUB_OUTPUT | |
fi | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: fetch | |
if: needs.fetch.outputs.ok | |
environment: | |
name: production | |
url: https://gis.ee/sadamad/ | |
steps: | |
- name: Checkout to main | |
uses: actions/checkout@v4 | |
- name: Download built files | |
uses: actions/download-artifact@v4 | |
with: | |
name: ports-files | |
path: ./public | |
- name: Set current date | |
id: date | |
run: | | |
echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
- name: Push data to git | |
run: | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
git commit -m "Data update ${{ steps.date.outputs.today }}" | |
git push | |
- name: Connect to server over SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy files | |
run: | | |
rsync -vrm ./public/ ${{ secrets.USERNAME }}@${{ secrets.HOST }}:${{ secrets.PATH }} |