Skip to content

Commit

Permalink
First simple version of Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
Flurb committed May 26, 2021
0 parents commit 37b8669
Show file tree
Hide file tree
Showing 332 changed files with 73,025 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Verify File Checksum action

This action verifies the checksum of a given file. If it passes, the Github Action passes.

## Inputs

### `file`

**Required** The file to check. If it's an URL, use the [`file:`](https://en.wikipedia.org/wiki/File_URI_scheme) protocol.

### `checksum`

**Required** The expected (hexadecimal) checksum of the given file.

### `algorithm`

**Required** The algorithm that has been used for calculating the checksum. Run `openssl list-message-digest-algorithms` in your terminal to check all available algorithms. Examples: `MD5`, `SHA512`, `DSA-SHA1`.

## Outputs

### `verify-result`

Does the checksum match with the given file.

## Example usage

```yaml
uses: actions/[email protected]
with:
file: 'file://assets.iec.ch/public/tc57/IEC_61850-6.2018.SCL.2007B4.full.zip'
checksum: 'd61da94836ff974fbd781ad1bc967039'
algorithm: 'MD5'
```
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Verify File Checksum'
description: 'Verify the checksum of a given file. If it passes, the Github Action passes.'
inputs:
file:
description: 'The file to check.'
required: true
checksum:
description: 'The expected checksum of the given file.'
required: true
algorithm:
description: 'The algorithm that has been used for calculating the checksum.'
required: true
default: 'MD5'
outputs:
verify-result:
description: 'Does the checksum match with the given file.'
runs:
using: 'node12'
main: 'index.js'
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const core = require('@actions/core');
const github = require('@actions/github');
const crypto = require('crypto');
const fs = require('fs')

try {
// Create a Hash based on the given algorithm.
const hashAccordingGivenAlgorithm = crypto.createHash(core.getInput('algorithm'));

// Calculating checksum for given file.
const streamGivenFile = fs.createReadStream(core.getInput('file'));
const calculatedChecksum = hashAccordingGivenAlgorithm.update(streamGivenFile).digest('hex');

const expectedChecksum = core.getInput('checksum');

console.log(`Calculated checksum: ${calculatedChecksum}`);
console.log(`Expected checksum: ${expectedChecksum}`);

if (calculatedChecksum == expectedChecksum) {
core.setOutput("verify-result", "Checksums are equal");
} else {
core.setOutput("verify-result", "Checksums are not equal");
core.setFailed(error.message);
}
} catch (error) {
core.setFailed(error.message);
}
185 changes: 185 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 37b8669

Please sign in to comment.