|
| 1 | +name: Sync and update Compliance Checks |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + # schedule: |
| 9 | + # - cron: "0 0 * * *" # Runs daily at midnight UTC |
| 10 | + # workflow_dispatch: # Allows manual triggering |
| 11 | + |
| 12 | +permissions: |
| 13 | + # We will create a pull request, so we need write permissions |
| 14 | + pull-requests: write |
| 15 | + # We will be committing to the repository, so we need write permissions |
| 16 | + contents: write |
| 17 | + |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync-and-update: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + services: |
| 24 | + postgres: |
| 25 | + image: postgres:17.2 |
| 26 | + env: |
| 27 | + POSTGRES_DB: dashboard |
| 28 | + POSTGRES_USER: openjs |
| 29 | + POSTGRES_PASSWORD: password |
| 30 | + ports: |
| 31 | + - 5432:5432 |
| 32 | + options: >- |
| 33 | + --health-cmd="pg_isready -U openjs" |
| 34 | + --health-interval=10s |
| 35 | + --health-timeout=5s |
| 36 | + --health-retries=5 |
| 37 | +
|
| 38 | + steps: |
| 39 | + # Checkout the current repository |
| 40 | + - name: Checkout Repository |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + # Create or switch to the chore/update-content branch |
| 44 | + - name: Create or Checkout Branch |
| 45 | + run: | |
| 46 | + git fetch origin chore/update-content || true |
| 47 | + git checkout chore/update-content || git checkout -b chore/update-content |
| 48 | +
|
| 49 | + # Clone the public repository and set it up |
| 50 | + - name: Clone OpenJS Foundation Dashboard |
| 51 | + run: | |
| 52 | + git clone https://github.com/secure-dashboards/openjs-foundation-dashboard.git temp-openjs-dashboard |
| 53 | + cd temp-openjs-dashboard |
| 54 | + npm install |
| 55 | + npm run db:migrate |
| 56 | + psql -U openjs -d dashboard -c "\copy (SELECT json_agg(t) FROM compliance_checks t) TO '../data/checks.json'" |
| 57 | + cd .. |
| 58 | + rm -rf temp-openjs-dashboard |
| 59 | + env: |
| 60 | + PGHOST: localhost |
| 61 | + PGUSER: openjs |
| 62 | + PGPASSWORD: password |
| 63 | + PGDATABASE: dashboard |
| 64 | + |
| 65 | + - name: Debug Git Changes (Before Commit Updated Checks) |
| 66 | + run: | |
| 67 | + git status |
| 68 | + git diff |
| 69 | +
|
| 70 | + # Commit the updated checks.json |
| 71 | + - name: Commit Updated Checks |
| 72 | + run: | |
| 73 | + git config user.name "GitHub Actions" |
| 74 | + git config user.email "[email protected]" |
| 75 | + git add -A |
| 76 | + git diff --cached --quiet || git commit -m "chore: sync with OpenJS Foundation Dashboard" |
| 77 | +
|
| 78 | + # Install dependencies for the current repository and generate site |
| 79 | + - name: Install Dependencies and Generate Site |
| 80 | + run: | |
| 81 | + npm install |
| 82 | + npm run populate-details |
| 83 | + npm run populate-implementations |
| 84 | +
|
| 85 | + - name: Debug Git Changes (Before Commit Updated Checks) |
| 86 | + run: | |
| 87 | + git status |
| 88 | + git diff |
| 89 | +
|
| 90 | + # Commit the generated site |
| 91 | + - name: Commit and Push Changes |
| 92 | + run: | |
| 93 | + git config user.name "GitHub Actions" |
| 94 | + git config user.email "[email protected]" |
| 95 | + git add -A |
| 96 | + git diff --cached --quiet || git commit -m "chore: auto-update details and implementations" |
| 97 | + git push origin chore/update-content |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + |
| 101 | + - name: Create Pull Request |
| 102 | + run: | |
| 103 | + PR_DATA=$(jq -n \ |
| 104 | + --arg title "Auto update content" \ |
| 105 | + --arg body "This PR updates the content." \ |
| 106 | + --arg head "chore/update-content" \ |
| 107 | + --arg base "main" \ |
| 108 | + --arg assignee "${{ github.actor }}" \ |
| 109 | + '{title: $title, body: $body, head: $head, base: $base, assignees: [$assignee]}') |
| 110 | + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 111 | + -H "Accept: application/vnd.github.v3+json" \ |
| 112 | + https://api.github.com/repos/${{ github.repository }}/pulls \ |
| 113 | + -d "$PR_DATA" |
0 commit comments