Skip to content

Commit

Permalink
refactor: revamp setup action with typescript (#18)
Browse files Browse the repository at this point in the history
This PR revamps setup action with typescript and 
1) add a new job to verify `dist` folder complication
2) update viable version to 1.1.0 and 1.0.1

---------

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah authored Sep 8, 2023
1 parent 8368cef commit 1aa9a00
Show file tree
Hide file tree
Showing 15 changed files with 7,368 additions and 155 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright The ORAS Authors.
# 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.

name: Check dist/

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:

jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: remove js files in dist/
run: find dist/ -type f \( -name "*.json" -o -name "*.js" -o -name "*.js.map" \) -delete
- name: Setup Node 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: npm
- name: Install dependencies
run: npm install
- name: Rebuild the dist/ directory
run: npm run build
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "DIFFERENCES DETECTED: 'npm run build' is needed after code changes. See status below:"
git diff
exit 1
fi
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
version:
- 0.15.1
- 1.0.0
- 1.0.1
- 1.1.0
fail-fast: true
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
version:
description: Version of ORAS CLI to install
required: false
default: 1.0.0
default: 1.1.0
runs:
using: node16
main: dist/index.js
main: dist/index.js
2 changes: 1 addition & 1 deletion dist/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Publishing

The content in this `dist` folder is auto-generated after editing `../index.js` by
The content in this `dist` folder is auto-generated by

```sh
npm run build
Expand Down
7,022 changes: 7,020 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/sourcemap-register.js

This file was deleted.

68 changes: 0 additions & 68 deletions index.js

This file was deleted.

111 changes: 36 additions & 75 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "setup-oras",
"version": "0.1.0",
"description": "Set up your GitHub Actions workflow with a specific version of ORAS",
"main": "index.js",
"scripts": {
"build": "ncc build index.js -o dist --source-map --minify --license licenses.txt"
"build": "ncc build src/setup.ts"
},
"repository": {
"type": "git",
Expand All @@ -19,6 +18,9 @@
"homepage": "https://github.com/oras-project/setup-oras#readme",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/tool-cache": "^2.0.1"
"@actions/tool-cache": "^2.0.1",
"@types/node": "^20.4.0",
"@vercel/ncc": "^0.36.1",
"typescript": "^5.2.2"
}
}
26 changes: 26 additions & 0 deletions src/lib/checksum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The ORAS Authors.
// 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.

import * as crypto from 'crypto';
import * as fs from 'fs';

// hash computes SH256 of file at path.
export function hash(path: string): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.createHash('sha256');
const stream = fs.createReadStream(path);
stream.on('error', err => reject(err));
stream.on('data', chunk => hash.update(chunk));
stream.on('end', () => resolve(hash.digest('hex')));
});
}
Loading

0 comments on commit 1aa9a00

Please sign in to comment.