Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
19 changes: 16 additions & 3 deletions function.js
Original file line number Diff line number Diff line change
@@ -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: "/",
});