diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4be042..9610bbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,16 +14,27 @@ jobs: steps: - name: Send repository update event + env: + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + REPO: ${{ github.repository }} + COMMIT: ${{ github.sha }} run: | curl -X POST -H "Authorization: token ${{ secrets.GH_PAT }}" \ -H "Accept: application/vnd.github.v3+json" \ + -H "Content-Type: application/json" \ https://api.github.com/repos/hubspotdev/CODE-Hub/actions/workflows/update-meta-repo.yml/dispatches \ - -d '{ - "ref": "main", - "inputs": { - "repo": "'"${{ github.repository }}"'", - "commit": "'"${{ github.sha }}"'", - "pr_title": "'"${{ github.event.pull_request.title }}"'", - "pr_url": "'"${{ github.event.pull_request.html_url }}"'" - } - }' + -d "$(jq -n \ + --arg repo "$REPO" \ + --arg commit "$COMMIT" \ + --arg pr_title "$PR_TITLE" \ + --arg pr_url "$PR_URL" \ + '{ + ref: "main", + inputs: { + repo: $repo, + commit: $commit, + pr_title: $pr_title, + pr_url: $pr_url + } + }')" diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml new file mode 100644 index 0000000..1c2f204 --- /dev/null +++ b/.github/workflows/run-test.yml @@ -0,0 +1,48 @@ +name: Run Tests + +on: + pull_request: + branches: [main] + +jobs: + run-tests: + name: Run Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:14 + env: + POSTGRES_DB: testdb + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + options: >- + --health-cmd="pg_isready" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + env: + DATABASE_URL: postgres://postgres:password@localhost:5432/testdb + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Install dependencies + run: npm install + + - name: Wait for DB to be ready + run: | + echo "Waiting for PostgreSQL to be ready..." + for i in {1..10}; do + pg_isready -h localhost -p 5432 && break + sleep 2 + done + + - name: Run tests + run: npm test diff --git a/.github/workflows/trigger-submodule-update.yml b/.github/workflows/trigger-submodule-update.yml index 36dd124..d64d7ef 100644 --- a/.github/workflows/trigger-submodule-update.yml +++ b/.github/workflows/trigger-submodule-update.yml @@ -12,16 +12,27 @@ jobs: steps: - name: Send repository update event + env: + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + REPO: ${{ github.repository }} + COMMIT: ${{ github.sha }} run: | curl -X POST -H "Authorization: token ${{ secrets.GH_PAT }}" \ -H "Accept: application/vnd.github.v3+json" \ + -H "Content-Type: application/json" \ https://api.github.com/repos/hubspotdev/CODE-Hub/dispatches \ - -d '{ - "event_type": "update-meta-repo", - "client_payload": { - "repo": "'"${{ github.repository }}"'", - "commit": "'"${{ github.sha }}"'", - "pr_title": "'"${{ github.event.pull_request.title }}"'", - "pr_url": "'"${{ github.event.pull_request.html_url }}"'" - } - }' + -d "$(jq -n \ + --arg repo "$REPO" \ + --arg commit "$COMMIT" \ + --arg pr_title "$PR_TITLE" \ + --arg pr_url "$PR_URL" \ + '{ + event_type: "update-meta-repo", + client_payload: { + repo: $repo, + commit: $commit, + pr_title: $pr_title, + pr_url: $pr_url + } + }')"