diff --git a/.github/scripts/README.md b/.github/scripts/README.md deleted file mode 100644 index fab1016..0000000 --- a/.github/scripts/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# GitHub Workflow Scripts - -This directory contains JavaScript modules used by GitHub Actions workflows to interact with the GitHub API. - -## Scripts - -### `comment-preview.js` -**Used by:** `deploy-preview.yml` -**Purpose:** Comments on pull requests with deploy preview URLs - -**Parameters:** -- `github` - GitHub API client from `actions/github-script` -- `context` - GitHub Actions context -- `deploymentUrl` - The URL of the deployed preview site - -**Behavior:** -- Finds existing preview comments and updates them -- Creates new comments if none exist -- Includes commit SHA and PR number in the comment - -### `cleanup-preview.js` -**Used by:** `cleanup-preview.yml` -**Purpose:** Complete cleanup workflow - deletes environment and adds comment - -**Parameters:** -- `github` - GitHub API client from `actions/github-script` -- `context` - GitHub Actions context - -**Behavior:** -- Deletes the deployment environment -- Adds cleanup confirmation comment -- Handles errors gracefully with fallback comments diff --git a/.github/scripts/cleanup-preview.js b/.github/scripts/cleanup-preview.js deleted file mode 100644 index b8ff87d..0000000 --- a/.github/scripts/cleanup-preview.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Performs complete cleanup for a pull request preview - * - Deletes the deployment environment - * - Adds a cleanup comment to the PR - * @param {Object} github - GitHub API client - * @param {Object} context - GitHub Actions context - */ -module.exports = async ({ github, context }) => { - const prNumber = context.issue.number; - const environmentName = `preview-pr-${prNumber}`; - - try { - // Delete the environment - await github.rest.repos.deleteAnEnvironment({ - owner: context.repo.owner, - repo: context.repo.repo, - environment_name: environmentName - }); - - console.log(`Environment ${environmentName} deleted successfully`); - - // Add cleanup comment to PR - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: `๐Ÿงน **Deploy Preview Cleaned Up** - -The preview environment for this PR has been automatically deleted. - ---- -*Cleanup completed for PR #${prNumber}*` - }); - - console.log(`Cleanup comment added to PR #${prNumber}`); - - } catch (error) { - console.log(`Cleanup failed for PR #${prNumber}: ${error.message}`); - - // Still try to add a comment even if environment deletion failed - try { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: `โš ๏ธ **Deploy Preview Cleanup** - -Attempted to clean up preview environment for PR #${prNumber}. -Environment may have already been deleted or was not found. - ---- -*Cleanup process completed*` - }); - console.log(`Fallback cleanup comment added to PR #${prNumber}`); - } catch (commentError) { - console.log(`Failed to add cleanup comment: ${commentError.message}`); - } - } -}; diff --git a/.github/scripts/comment-preview.js b/.github/scripts/comment-preview.js deleted file mode 100644 index 3d4991e..0000000 --- a/.github/scripts/comment-preview.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Comments on a pull request with the deploy preview URL - * @param {Object} github - GitHub API client - * @param {Object} context - GitHub Actions context - * @param {string} deploymentUrl - The URL of the deployed preview - */ -module.exports = async ({ github, context, deploymentUrl }) => { - const prNumber = context.issue.number; - - // Find existing preview comment - const comments = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - }); - - const existingComment = comments.data.find(comment => - comment.body.includes('๐Ÿš€ Deploy Preview') - ); - - const commentBody = `๐Ÿš€ **Deploy Preview** for PR #${prNumber} is ready! - -**Preview URL:** ${deploymentUrl} - -This preview will be updated automatically when you push new changes to this PR. - ---- -*Deployed from commit: ${context.sha}*`; - - if (existingComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: existingComment.id, - body: commentBody - }); - console.log(`Updated existing preview comment for PR #${prNumber}`); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - console.log(`Created new preview comment for PR #${prNumber}`); - } -}; diff --git a/.github/workflows/cleanup-preview.yml b/.github/workflows/cleanup-preview.yml deleted file mode 100644 index 367394e..0000000 --- a/.github/workflows/cleanup-preview.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Cleanup Preview - -on: - pull_request: - types: [closed] - workflow_dispatch: - -permissions: - deployments: write - pull-requests: write - -jobs: - cleanup: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Delete deployment environment and comment - run: | - node .github/scripts/cleanup-preview.js - diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml deleted file mode 100644 index 2fdffb0..0000000 --- a/.github/workflows/deploy-preview.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Deploy Preview - -on: - pull_request: - branches: - - main - types: [opened, synchronize, reopened] - workflow_dispatch: - -concurrency: - group: deploy-preview-${{ github.event.pull_request.number }} - cancel-in-progress: true - -permissions: - contents: read - pages: write - id-token: write - pull-requests: write - deployments: write - -jobs: - build-preview: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install Antora - run: npm install antora - - - name: Generate Site - run: npx antora antora-playbook.yml - - - name: Disable Jekyll - run: touch build/site/.nojekyll - - - name: Upload Preview Artifact - uses: actions/upload-artifact@v4 - with: - name: preview-site-${{ github.event.pull_request.number }} - path: ./build/site - retention-days: 30 - - deploy-preview: - needs: build-preview - runs-on: ubuntu-latest - - environment: - name: preview-pr-${{ github.event.pull_request.number }} - url: ${{ steps.deploy.outputs.page_url }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download Preview Artifact - uses: actions/download-artifact@v4 - with: - name: preview-site-${{ github.event.pull_request.number }} - path: ./site - - - name: Setup Pages - uses: actions/configure-pages@v4 - - - name: Upload Pages Artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ./site - - - name: Deploy to GitHub Pages - id: deploy - uses: actions/deploy-pages@v4 - - - name: Delete deployment environment and comment - run: | - node .github/scripts/comment-preview.js diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..ac60827 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,48 @@ +name: Deploy PR previews # Name of your workflow + +on: + pull_request: + types: [opened, reopened, synchronize, closed] # Trigger on PR open, reopen, sync, or close + +permissions: + contents: write + pages: write + id-token: write + pull-requests: write + deployments: write + +jobs: + deploy-preview: + runs-on: ubuntu-latest # Use a suitable runner environment + + steps: + - uses: actions/checkout@v4 # Checkout the code from the pull request + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Antora + run: npm install antora + + - name: Generate Site + run: npx antora antora-playbook.yml + + - name: Disable Jekyll + run: touch build/site/.nojekyll + + - name: Deploy preview # Deploy the built site as a preview + uses: rossjrw/pr-preview-action@v1 # Use the pr-preview-action + with: + source-dir: ./build/site # Directory containing the built site files + preview-branch: test # The branch to deploy previews to (usually gh-pages for GitHub Pages) + umbrella-dir: pr-preview # Directory within the preview branch to store previews + action: auto # Automatically handles deployment and cleanup (deploy/remove) + + - name: Remove preview on closed PR # Remove the preview when the PR is closed + if: github.event.action == 'closed' # Condition to run only on PR close + uses: rossjrw/pr-preview-action@v1 # Use the pr-preview-action again + with: + action: remove # Specify the action to remove the preview + umbrella-dir: pr-preview # Directory where previews are stored diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 3bd2bd9..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Publish to GitHub Pages - -on: - push: - branches: - - main - workflow_dispatch: - -concurrency: - group: github-pages - cancel-in-progress: false - -permissions: - contents: read - pages: write - id-token: write - -jobs: - build: - runs-on: ubuntu-latest - - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install Antora - run: npm install antora - - - name: Generate Site - run: npx antora antora-playbook.yml - - - name: Post-process paths for VC context/schema docs - run: | - mv build/site/identity/1.1/_attachments/ica build/site/identity/1.1/ica - - - name: Disable Jekyll - run: touch .nojekyll - - - name: Upload Artifacts - uses: actions/upload-pages-artifact@v3 - with: - path: ./build/site - - deploy: - needs: build - runs-on: ubuntu-latest - - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4