diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 007784c..f5550c6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,20 +9,27 @@ jobs: deploy: name: deploy-gcf runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + + - id: 'auth' + uses: google-github-actions/auth@v2 + with: + credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY }}' + - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v2 with: # probot/example-google-cloud-function credentials provided by @bcoe project_id: ${{ secrets.PROJECT_ID }} - service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} - export_default_credentials: true + - name: Deploy to GCF run: | gcloud functions deploy example-google-cloud-function \ - --runtime nodejs12 \ + --runtime=nodejs20 \ --allow-unauthenticated \ --trigger-http \ - --entry-point probotApp \ + --entry-point=probotApp \ --set-env-vars APP_ID="${{secrets.APP_ID}}",PRIVATE_KEY="${{secrets.PRIVATE_KEY}}",WEBHOOK_SECRET="${{secrets.WEBHOOK_SECRET}}" diff --git a/function.js b/function.js index 0ddf609..8ad0acd 100644 --- a/function.js +++ b/function.js @@ -1,4 +1,17 @@ -const { createNodeMiddleware, createProbot } = require("probot"); -const app = require("./app"); +// Use CommonJS syntax for compatibility with Node.js. +const { createNodeMiddleware, Probot } = require("probot"); +// Import the Probot app function. +const appFn = require("./app.js"); -exports.probotApp = createNodeMiddleware(app, { probot: createProbot(), webhooksPath: "/" }); +// Initialize Probot with environment variables. +const probot = new Probot({ + appId: process.env.APP_ID, + privateKey: process.env.PRIVATE_KEY?.replace(/\\n/g, '\n'), // Fix newlines in RSA keys + secret: process.env.WEBHOOK_SECRET, +}); + +// This exports the Probot app as middleware for use in a serverless environment. +module.exports.probotApp = createNodeMiddleware(appFn, { + probot: probot, + webhooksPath: "/", +});