make webhook when deploy #315
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: Checks | |
on: | |
push: | |
branches: | |
- '**' | |
workflow_dispatch: | |
# BOT_TOKEN is what I want to use most of the times, | |
# But deploy hates is for no reason, so I use | |
# GITHUB_TOKEN just for the deploy job | |
jobs: | |
format_repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} # Make sure PR is checked out | |
- name: Install Prettier | |
run: npm install prettier | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Create Virtual Environment | |
run: python -m venv venv | |
- name: Activate venv | |
run: source venv/bin/activate | |
- name: Run pre_commit.py | |
run: python pys/pre_commit.py --format | |
- name: Commit changes | |
run: | | |
git config --global user.name "NSPBot911" | |
git config --global user.email ${{ secrets.BOT_EMAIL }} | |
git add -A | |
if git diff-index --quiet HEAD --; then | |
echo "No changes to commit" | |
else | |
git commit -m "[actions] Post Commit Checks Completed" -m "$(git log -1 --pretty=format:'%an') forgot to run pre_commit.py --format" -m "skip-checks: true" | |
git push | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} | |
deploy_page: | |
needs: format_repo | |
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'skip-deploy') | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Replace server IP in JavaScript | |
run: | | |
sed -i 's|const serverip = "localhost";|const serverip = "${{ secrets.IP_FOR_SERVER }}";|g' webUI/app.js | |
- name: Upload Artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./webUI | |
retention-days: 1 | |
- name: Deploy to GitHub Pages | |
uses: actions/deploy-pages@v4 | |
- name: Get Artifact ID | |
run: | | |
artifacts=$(curl -s -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/artifacts) | |
artifact_id=$(echo "$artifacts" | jq -r '.artifacts[0] | select(.name == "github-pages") | .id') | |
echo "Artifact ID: $artifact_id" | |
echo "artifact_id=$artifact_id" >> $GITHUB_ENV | |
- name: Delete Artifact | |
if: env.artifact_id != '' | |
run: | | |
curl -X DELETE -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id | |
- name: Notify Discord | |
uses: sarisia/[email protected] | |
with: | |
webhook: ${{ secrets.LOG_HOOK }} | |
title: Page Deployed! | |
description: "Online at https://becomtweaks.github.io/resource-packs/" | |
avatar_url: "https://avatars.githubusercontent.com/u/176916861?v=4" | |
username: "NSPBot911" | |
nodetail: true | |
update_server: | |
needs: format_repo | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'skip-update') && contains(github.event.head_commit.message, 'pack') | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get latest commit title | |
id: get_commit | |
run: | | |
echo "commit_title=$(git log -1 --pretty=%s)" >> $GITHUB_ENV | |
- name: Trigger server-backend workflow | |
run: | | |
curl -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ | |
https://api.github.com/repos/BEComTweaks/server-backend/actions/workflows/106751072/dispatches \ | |
-d "{\"ref\":\"main\", \"inputs\":{\"title\":\"resource-packs: ${{ env.commit_title }}\"}}" |