-
Notifications
You must be signed in to change notification settings - Fork 267
Create GitHub Actions Test Setup #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cclauss
merged 14 commits into
mapbox:master
from
ronilan:Test-Create-GitHub-Actions-Test-Setup
Apr 25, 2025
+568
−196
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b539991
Refactored mock setup.
ronilan 6c02fd8
Refactored test setup.
ronilan 3c2824e
Refactored test apps and increased test coverage
ronilan f505160
Added service script to switch test apps bucket from mock to S3 and v…
ronilan 2752856
Fix CodeQL and rebase errors.
ronilan 079aed0
Added service script to switch test apps bucket from mock to S3 and v…
ronilan d483fab
Created GitHub Actions Test Setup
ronilan 583e5ad
Modified existing configurations to work with GitHub Actions Test setup.
ronilan df6085a
Updated github actions to only test node 18, 20, 22.
ronilan 706840f
Trying windows-latest
ronilan 65f2bbe
Removed nw tests from GitHub push actions as they are not working rig…
ronilan ded7e4d
Changed push to bucket only tests.
ronilan cf63998
Changed test name
ronilan 05c4d24
Changed test name
ronilan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: S3 Bucket Test | ||
|
|
||
| on: | ||
| push: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test-on-os-node-matrix: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest, windows-latest] | ||
| node: [18, 20, 22] | ||
ronilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| env: | ||
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| S3_BUCKET: ${{ secrets.S3_BUCKET }} | ||
|
|
||
| name: Test S3 Bucket - Node ${{ matrix.node }} on ${{ matrix.os }} | ||
|
|
||
| steps: | ||
| - name: Checkout ${{ github.ref }} | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup node ${{ matrix.node }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node }} | ||
|
|
||
| - name: NPM Install | ||
| run: npm install | ||
|
|
||
| - name: Show Environment Info | ||
| run: | | ||
| printenv | ||
| node --version | ||
| npm --version | ||
|
|
||
| - name: Run S3 Tests (against ${{ env.S3_BUCKET }} bucket) | ||
| run: | | ||
| npm run bucket ${{ env.S3_BUCKET }} | ||
| npm run test:s3 | ||
| if: ${{ env.S3_BUCKET != '' }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = http_mock; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const nock = require('nock'); | ||
| const os = require('os'); | ||
|
|
||
| const log = require('npmlog'); | ||
| log.disableProgress(); // disable the display of a progress bar | ||
| log.heading = 'node-pre-gyp'; // differentiate node-pre-gyp's logs from npm's | ||
|
|
||
| function http_mock() { | ||
| log.warn('mocking http requests to s3'); | ||
|
|
||
| const basePath = `${os.tmpdir()}/mock`; | ||
|
|
||
| nock(new RegExp('([a-z0-9]+[.])*s3[.]us-east-1[.]amazonaws[.]com')) | ||
| .get(() => true) //a function that always returns true is a catch all for nock | ||
| .reply( | ||
| (uri) => { | ||
| const bucket = 'npg-mock-bucket'; | ||
| const mockDir = uri.indexOf(bucket) === -1 ? `${basePath}/${bucket}` : basePath; | ||
| const filepath = path.join(mockDir, uri.replace(new RegExp('%2B', 'g'), '+')); | ||
|
|
||
| try { | ||
| fs.accessSync(filepath, fs.constants.R_OK); | ||
| } catch (e) { | ||
| return [404, 'not found\n']; | ||
| } | ||
|
|
||
| // mock s3 functions write to disk | ||
| // return what is read from it. | ||
| return [200, fs.createReadStream(filepath)]; | ||
| } | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = s3_mock; | ||
|
|
||
| const AWSMock = require('mock-aws-s3'); | ||
| const os = require('os'); | ||
|
|
||
| const log = require('npmlog'); | ||
| log.disableProgress(); // disable the display of a progress bar | ||
| log.heading = 'node-pre-gyp'; // differentiate node-pre-gyp's logs from npm's | ||
|
|
||
| function s3_mock() { | ||
| log.warn('mocking s3 operations'); | ||
|
|
||
| AWSMock.config.basePath = `${os.tmpdir()}/mock`; | ||
|
|
||
| const s3 = AWSMock.S3(); | ||
|
|
||
| // wrapped callback maker. fs calls return code of ENOENT but AWS.S3 returns | ||
| // NotFound. | ||
| const wcb = (fn) => (err, ...args) => { | ||
| if (err && err.code === 'ENOENT') { | ||
| err.code = 'NotFound'; | ||
| } | ||
| return fn(err, ...args); | ||
| }; | ||
|
|
||
| return { | ||
| listObjects(params, callback) { | ||
| return s3.listObjects(params, wcb(callback)); | ||
| }, | ||
| headObject(params, callback) { | ||
| return s3.headObject(params, wcb(callback)); | ||
| }, | ||
| deleteObject(params, callback) { | ||
| return s3.deleteObject(params, wcb(callback)); | ||
| }, | ||
| putObject(params, callback) { | ||
| return s3.putObject(params, wcb(callback)); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| 'use strict'; | ||
|
|
||
| // script changes the bucket name set in package.json of the test apps. | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // http mock (lib/mock/http.js) sets 'npg-mock-bucket' as default bucket name. | ||
| // when providing no bucket name as argument, script will set | ||
| // all apps back to default mock settings. | ||
| const bucket = process.argv[2] || 'npg-mock-bucket'; | ||
|
|
||
| const root = '../test'; | ||
| const rootPath = path.resolve(__dirname, root); | ||
| const dirs = fs.readdirSync(rootPath).filter((fileorDir) => fs.lstatSync(path.resolve(rootPath, fileorDir)).isDirectory()); | ||
|
|
||
| dirs.forEach((dir) => { | ||
| const pkg = require(`${root}/${dir}/package.json`); // relative path | ||
|
|
||
| // bucket specified as part of s3 virtual host format (auto detected by node-pre-gyp) | ||
| const keys = ['host', 'staging_host', 'production_host']; | ||
| keys.forEach((item) => { | ||
ronilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (pkg.binary[item]) { | ||
|
|
||
| // match the bucket part of the url | ||
| const match = pkg.binary[item].match(/^https:\/\/(.+)(?:\.s3[-.].*)$/i); | ||
| if (match) { | ||
| pkg.binary[item] = pkg.binary[item].replace(match[1], bucket); | ||
| console.log(`Success: set ${dir} ${item} to ${pkg.binary[item]}`); | ||
| } | ||
| } | ||
| }); | ||
| // bucket is specified explicitly | ||
| if (pkg.binary.bucket) { | ||
| pkg.binary.bucket = bucket; | ||
| console.log(`Set ${dir} bucket to ${pkg.binary.bucket}`); | ||
| } | ||
|
|
||
| // make sure bucket name is set in the package (somewhere) else this is an obvious error. | ||
| // most likely due to manual editing of the json resulting in unusable format | ||
| const str = JSON.stringify(pkg, null, 4); | ||
| if (str.indexOf(bucket) !== -1) { | ||
| fs.writeFileSync(path.join(path.resolve(rootPath, dir), 'package.json'), str + '\n'); | ||
| } else { | ||
| throw new Error(`Error: could not set ${dir}. Manually check package.json`); | ||
| } | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.