adding pr support
Some checks failed
Some checks failed
This commit is contained in:
168
.gitea/workflows/pull-request.yaml
Normal file
168
.gitea/workflows/pull-request.yaml
Normal file
@@ -0,0 +1,168 @@
|
||||
name: Build Pull Request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
|
||||
env:
|
||||
ARCHIVE_NAME: vision-start-pr-${{ gitea.event.pull_request.number }}.zip
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Pull Request Archive
|
||||
runs-on: ubuntu-amd64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Set up required tools
|
||||
run: sudo apt-get install zip wget -y
|
||||
|
||||
- name: Install JS dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run build
|
||||
run: |
|
||||
bash scripts/prepare_release.sh
|
||||
npm run build
|
||||
|
||||
- name: Prepare archive
|
||||
run: |
|
||||
mv dist vision-start/
|
||||
mv extension vision-start/
|
||||
mv manifest.json vision-start/
|
||||
|
||||
- name: Create zip archive
|
||||
run: |
|
||||
cd vision-start
|
||||
zip -r ../${{ env.ARCHIVE_NAME }} *
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pr-release-zip
|
||||
path: ${{ env.ARCHIVE_NAME }}
|
||||
|
||||
capture_screenshots:
|
||||
name: Capture Pull Request Screenshots
|
||||
runs-on: ubuntu-amd64
|
||||
needs: build
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Set up required tools
|
||||
run: sudo apt-get install unzip -y
|
||||
|
||||
- name: Install JS dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Download build artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: pr-release-zip
|
||||
|
||||
- name: Unpack build artifact
|
||||
run: unzip -q ${{ env.ARCHIVE_NAME }}
|
||||
|
||||
- name: Install Playwright Chromium
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Capture screenshots
|
||||
run: npm run capture:screenshots
|
||||
|
||||
- name: Upload screenshot artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pr-screenshots
|
||||
path: |
|
||||
screenshots/home.png
|
||||
screenshots/editing.png
|
||||
screenshots/configuration.png
|
||||
|
||||
publish_screenshot_preview:
|
||||
name: Publish Pull Request Screenshot Preview
|
||||
runs-on: ubuntu-amd64
|
||||
needs: capture_screenshots
|
||||
if: ${{ gitea.event.pull_request.head.repo.full_name == gitea.repository }}
|
||||
permissions:
|
||||
actions: read
|
||||
issues: write
|
||||
steps:
|
||||
- name: Set up required tools
|
||||
run: sudo apt-get install curl jq -y
|
||||
|
||||
- name: Download screenshot artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: pr-screenshots
|
||||
path: screenshots
|
||||
|
||||
- name: Update pull request screenshot preview
|
||||
continue-on-error: true
|
||||
env:
|
||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
||||
GITEA_TOKEN: ${{ gitea.token }}
|
||||
REPOSITORY: ${{ gitea.repository }}
|
||||
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
OWNER="${REPOSITORY%%/*}"
|
||||
REPO="${REPOSITORY#*/}"
|
||||
MARKER='<!-- vision-start-pr-screenshots -->'
|
||||
COMMENTS_URL="$GITEA_API_URL/repos/$OWNER/$REPO/issues/$PR_NUMBER/comments"
|
||||
COMMENTS=$(curl -fsS -H "Authorization: token $GITEA_TOKEN" "$COMMENTS_URL")
|
||||
COMMENT_ID=$(printf '%s' "$COMMENTS" | jq -r --arg marker "$MARKER" '.[] | select(.body | contains($marker)) | .id' | tail -n 1)
|
||||
|
||||
if [ -z "$COMMENT_ID" ] || [ "$COMMENT_ID" = "null" ]; then
|
||||
PAYLOAD=$(jq -n --arg body "$MARKER" '{body: $body}')
|
||||
COMMENT_ID=$(curl -fsS -X POST \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data "$PAYLOAD" \
|
||||
"$COMMENTS_URL" | jq -r '.id')
|
||||
fi
|
||||
|
||||
ASSETS_URL="$GITEA_API_URL/repos/$OWNER/$REPO/issues/comments/$COMMENT_ID/assets"
|
||||
for ASSET_ID in $(curl -fsS -H "Authorization: token $GITEA_TOKEN" "$ASSETS_URL" | jq -r '.[].id'); do
|
||||
curl -fsS -X DELETE -H "Authorization: token $GITEA_TOKEN" "$ASSETS_URL/$ASSET_ID"
|
||||
done
|
||||
|
||||
upload_asset() {
|
||||
curl -fsS -X POST \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-F "attachment=@$1;type=image/png" \
|
||||
"$ASSETS_URL" | jq -r '.browser_download_url'
|
||||
}
|
||||
|
||||
HOME_URL=$(upload_asset screenshots/home.png)
|
||||
EDITING_URL=$(upload_asset screenshots/editing.png)
|
||||
CONFIGURATION_URL=$(upload_asset screenshots/configuration.png)
|
||||
BODY=$(printf '%s\n\n%s\n\n%s\n%s\n\n%s\n%s\n\n%s\n%s' \
|
||||
"$MARKER" \
|
||||
'## Visual preview' \
|
||||
'### Home' \
|
||||
"" \
|
||||
'### Editing' \
|
||||
"" \
|
||||
'### Configuration' \
|
||||
"")
|
||||
PAYLOAD=$(jq -n --arg body "$BODY" '{body: $body}')
|
||||
curl -fsS -X PATCH \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
--data "$PAYLOAD" \
|
||||
"$GITEA_API_URL/repos/$OWNER/$REPO/issues/comments/$COMMENT_ID"
|
||||
@@ -102,7 +102,7 @@ jobs:
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build, virus-total-check]
|
||||
needs: [build, virus-total-check, capture_screenshots]
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
@@ -110,6 +110,11 @@ jobs:
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-zip
|
||||
- name: Download screenshot artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: release-screenshots
|
||||
path: release-screenshots
|
||||
- name: Release zip
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
@@ -120,7 +125,11 @@ jobs:
|
||||
**Virus Total Detection Ratio:** ${{ needs.virus-total-check.outputs.detection-ratio }}
|
||||
name: ${{ gitea.ref_name }}
|
||||
tag_name: ${{ gitea.ref_name }}
|
||||
files: vision-start-${{ gitea.ref_name }}.zip
|
||||
files: |
|
||||
vision-start-${{ gitea.ref_name }}.zip
|
||||
release-screenshots/home.png
|
||||
release-screenshots/editing.png
|
||||
release-screenshots/configuration.png
|
||||
|
||||
build_vision_start:
|
||||
name: Build Vision Start Image
|
||||
@@ -184,3 +193,36 @@ jobs:
|
||||
cd ${{ secrets.PROD_DIR }}
|
||||
docker compose pull
|
||||
docker compose up -d --force-recreate
|
||||
|
||||
capture_screenshots:
|
||||
name: Capture Vision Start Screenshots
|
||||
runs-on: ubuntu-amd64
|
||||
needs: deploy_vision_start
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install JS dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Install Playwright Chromium
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Capture release screenshots
|
||||
env:
|
||||
SCREENSHOT_BASE_URL: http://vision-start.ivanch.me
|
||||
run: npm run capture:screenshots
|
||||
|
||||
- name: Upload release screenshots
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: release-screenshots
|
||||
path: |
|
||||
screenshots/home.png
|
||||
screenshots/editing.png
|
||||
screenshots/configuration.png
|
||||
|
||||
Reference in New Issue
Block a user