Skip to content

Commit

Permalink
Update action.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
eq19 committed Sep 27, 2024
1 parent bd1cf3f commit 2114235
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 25 deletions.
16 changes: 16 additions & 0 deletions .github/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ inputs:
action_path:
description: 'Path to the requirements file'
required: true
hub_username:
description: Username for Docker Hub
default: ${{ github.actor }}
required: true
hub_password:
description: Docker Hub authentication token
required: true
hub_token:
description: Docker Hub authentication token
required: true

runs:
using: composite
Expand Down Expand Up @@ -58,6 +68,12 @@ runs:
if [ $? -eq 0 ]; then exit 1; fi
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ inputs.hub_username }}
password: ${{ inputs.hub_token }}

- uses: actions/setup-python@v5
if: runner.os != 'Windows'
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/actions/1-ubuntu/1-maps/2-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ outputs:
runs:
using: composite
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ inputs.hub_username }}
password: ${{ inputs.hub_token }}

- name: 🚀 Initiate Lexer
uses: devcontainers/ci@v0.3
with:
Expand Down
31 changes: 22 additions & 9 deletions .github/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import express from 'express';
const app = express();
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

app.get('/', (req, res) => {
const name = process.env.NAME || 'World';
res.send(`Hello ${name}!`);
});
'use strict';

// [START functions_helloworld_get]
const functions = require('@google-cloud/functions-framework');

const port = parseInt(process.env.PORT) || 8080;
app.listen(port, () => {
console.log(`helloworld: listening on port ${port}`);
// Register an HTTP function with the Functions Framework that will be executed
// when you make an HTTP request to the deployed function's endpoint.
functions.http('helloGET', (req, res) => {
res.send('Hello World!');
});
// [END functions_helloworld_get]
27 changes: 17 additions & 10 deletions .github/functions/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"name": "helloworld",
"description": "Simple hello world sample in Node",
"version": "1.0.0",
"name": "nodejs-docs-samples-functions-hello-world-get",
"version": "0.0.1",
"private": true,
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": ">=16.0.0"
},
"author": "Google LLC",
"license": "Apache-2.0",
"scripts": {
"test": "c8 mocha -p -j 2 test/*.test.js --timeout=6000 --exit"
},
"dependencies": {
"express": "^4.17.1"
"@google-cloud/functions-framework": "^3.1.0"
},
"devDependencies": {
"c8": "^10.0.0",
"gaxios": "^6.0.0",
"mocha": "^10.0.0",
"wait-port": "^1.0.4"
}
}
54 changes: 54 additions & 0 deletions .github/functions/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const assert = require('assert');
const {request} = require('gaxios');
const {exec} = require('child_process');
const waitPort = require('wait-port');

const startFF = async (target, signature, port) => {
const ff = exec(
`npx functions-framework --target=${target} --signature-type=${signature} --port=${port}`
);
await waitPort({host: 'localhost', port});
return ff;
};

const httpInvocation = (fnUrl, port) => {
const baseUrl = `http://localhost:${port}`;

// GET request
return request({
url: `${baseUrl}/${fnUrl}`,
});
};

describe('index.test.js', () => {
describe('functions_helloworld_get helloGET', () => {
const PORT = 8081;
let ffProc;

before(async () => {
ffProc = await startFF('helloGET', 'http', PORT);
});

after(() => ffProc.kill());

it('helloGET: should print hello world', async () => {
const response = await httpInvocation('helloGET', PORT);
assert.strictEqual(response.status, 200);
assert.strictEqual(response.data, 'Hello World!');
});
});
});

0 comments on commit 2114235

Please sign in to comment.