Skip to content

Commit

Permalink
Implemented upload-buildinfo-outputs action.
Browse files Browse the repository at this point in the history
- JavaScript action created, source code available in src folder.
- Jest unit tests added, code available in __tests__ folder.
- Packaged code for GitHub actions available in dist/index.js file.
  • Loading branch information
ChristopheClermont committed Mar 12, 2024
1 parent fa6b6df commit df3d8ea
Show file tree
Hide file tree
Showing 34 changed files with 147,160 additions and 25,263 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
dist/
node_modules/
coverage/
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf

dist/** -diff linguist-generated=true
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test Javascript Action
on: [push]

jobs:
test:

runs-on: ubuntu-latest

name: Test upload
steps:

- uses: actions/checkout@v4

- name: Start Javascript action to upload buildinfo's artifacts
uses: sentrysoftware/upload-buildinfo-outputs@main
with:
compression-level: 0
104 changes: 103 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
node_modules/
# Dependency directory
node_modules

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*

# IDE files
.idea
.vscode
*.code-workspace
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
coverage/
16 changes: 16 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "avoid",
"proseWrap": "always",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "lf"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
# Hello world javascript action
# GitHub Javascript Action Upload Buildinfo Outputs

This action prints "Hello World" or "Hello" + the name of a person to greet to the log.
This action prints searches for `buildinfo` files in project, then upload artifacts declared as outputs in Github build artifacts.

## Inputs

### `who-to-greet`
### `search-path`

**Required** The name of the person to greet. Default `"World"`.
[Glob](https://en.wikipedia.org/wiki/Glob_(programming)) pattern to search for `buildinfo` files. By default `**/*.buildinfo`.

## Outputs
### `file-encoding`

Encoding used by the `buildinfo` files. Default to `utf-8`.

### `retention-days`

Duration after which artifact will expire in days. If unspecified, defaults to repository/org retention settings (the limit of this value).

### `compression-level`

### `time`
The level of compression for Zlib to be applied to the artifact archive. Default to `6`.

- `0`: No compression
- `1`: Best speed
- `6`: Default compression (same as GNU Gzip)
- `9`: Best compression

### `overwrite`

Whether or not to replace an existing artifact with the same name. Default to `false`.

## Outputs

The time we greeted you.
The action does not provides output.

## Example usage

```yaml
uses: actions/hello-world-javascript-action@e76147da8e5c81eaf017dede5645551d4b94427b
uses: sentrysoftware/upload-buildinfo-outputs@main
with:
who-to-greet: 'Mona the Octocat'
search-path: '**/*.buildinfo'
file-encoding: 'utf-8'
retention-days: 10
compression-level: 6
overwrite: false
```
35 changes: 35 additions & 0 deletions __tests__/buildinfo.error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const buildinfo = require('../src/buildinfo.js');
const inputs = require('../src/inputs.js');

jest.mock('fs', () => ({
promises: {
access: jest.fn()
},
readFileSync: jest.fn().mockRejectedValue(() => { throw new Error('Cannot read.'); }),
}));

jest.mock('path', () => ({
dirname: jest.fn().mockReturnValue('/path/to'),
join: jest.fn().mockImplementation((folder, name) => folder + '/' + name),
}));

describe('test readBuildInfoFiles', () => {

beforeEach(() => {
jest.clearAllMocks();
});

it('parse buildinfo', () => {

const readBuildInfoFilesMock = jest.spyOn(buildinfo, 'readBuildInfoFiles');

// Mock other modules
jest.spyOn(inputs, 'getFileEncoding').mockImplementation(() => {
return 'utf-8';
});

expect(buildinfo.readBuildInfoFiles(['/path/to/buildinfo1'])).rejects.toMatch('error');

});

});
75 changes: 75 additions & 0 deletions __tests__/buildinfo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const buildinfo = require('../src/buildinfo.js');
const inputs = require('../src/inputs.js');

const testBuildInfo = `# https://reproducible-builds.org/docs/jvm/
buildinfo.version=1.0-SNAPSHOT
name=Dummy Project Module
group-id=org.sentrysoftware
artifact-id=dummy-module
version=1.0.00
# source information
source.scm.uri=scm:git:https://github.com/sentrysoftware/xxx.git
source.scm.tag=v1.0.00
# build instructions
build-tool=mvn
# build environment information (simplified for reproducibility)
java.version=17
os.name=Unix
# Maven rebuild instructions and effective environment
# output
outputs.0.groupId=org.sentrysoftware
outputs.0.filename=dummy-module-1.0.00.pom
outputs.0.length=287
outputs.0.checksums.sha512=cbd2e4dc6ddd5590ecf4d7aec5a5a368121e21494611c6b8081461d669e0c9c8e40356bcbdf9f9ce9f4eabe5be0af2f4e93af3301db120e5fa5f7ad9b3ab700f
outputs.1.groupId=org.sentrysoftware
outputs.1.filename=dummy-module-1.0.00.txt
outputs.1.length=22
outputs.1.checksums.sha512=7b69215e1fc256d55f7a4cbb7daf5ca0cf63358a3d2bf85bb12f954646502afaef074f1d517184cf4e42271f4965f651850c76c1b6c90ff79f09a778e8c93a3d`;

jest.mock('fs', () => ({
promises: {
access: jest.fn()
},
readFileSync: jest.fn().mockReturnValue(testBuildInfo),
}));

jest.mock('path', () => ({
dirname: jest.fn().mockReturnValue('/path/to'),
join: jest.fn().mockImplementation((folder, name) => folder + '/' + name),
}));

describe('test readBuildInfoFiles', () => {

beforeEach(() => {
jest.clearAllMocks();
});

it('parse buildinfo', () => {

const readBuildInfoFilesMock = jest.spyOn(buildinfo, 'readBuildInfoFiles');

// Mock other modules
jest.spyOn(inputs, 'getFileEncoding').mockImplementation(() => {
return 'utf-8';
});

const outputs = buildinfo.readBuildInfoFiles(['/path/to/buildinfo1']);

expect(readBuildInfoFilesMock).toHaveBeenCalled();

expect(outputs).toStrictEqual([
'/path/to/dummy-module-1.0.00.pom',
'/path/to/dummy-module-1.0.00.txt'
]);

});

});
14 changes: 14 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { run } = require('../src/run.js');

// Mock the action's entrypoint
jest.mock('../src/run.js', () => ({
run: jest.fn()
}));

describe('test index', () => {
it('verifies index calls run', async () => {
require('../src/index.js');

expect(run).toHaveBeenCalled();
})
});
Loading

0 comments on commit df3d8ea

Please sign in to comment.