Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit c37e97b

Browse files
committed
Add hash verification for Linux and Windows
1 parent e526296 commit c37e97b

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.github/workflows/build.yml

+16-9
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@ jobs:
2424
os: [ ubuntu-latest, macos-latest, windows-latest ]
2525

2626
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
30+
# Node 14 matches the version of Node used by VS Code when this was
31+
# written, but it should be updated when VS Code updates its Node version.
32+
# Node needs to be installed before OS-specific setup so that we can run
33+
# the hash verification script.
34+
- name: Use Node 14.x
35+
uses: actions/setup-node@v2
36+
with:
37+
node-version: 14.x
38+
2739
- name: Windows setup
2840
if: ${{ matrix.os == 'windows-latest' }}
2941
run: |
3042
curl -LO https://downloads.arduino.cc/arduino-1.8.19-windows.zip
43+
node build/checkHash.js arduino-1.8.19-windows.zip `
44+
c704a821089eab2588f1deae775916219b1517febd1dd574ff29958dca873945
3145
7z x arduino-1.8.19-windows.zip -o"$Env:TEMP\arduino-ide"
3246
echo "$Env:TEMP\arduino-ide\arduino-1.8.19" | Out-File -FilePath $env:GITHUB_PATH -Append
3347
- name: Linux setup
@@ -36,6 +50,8 @@ jobs:
3650
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0
3751
sleep 3
3852
wget https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz -P /home/$USER
53+
node build/checkHash.js /home/$USER/arduino-1.8.19-linux64.tar.xz \
54+
eb68bddc1d1c0120be2fca1350a03ee34531cf37f51847b21210b6e70545bc9b
3955
tar -xvf /home/$USER/arduino-1.8.19-linux64.tar.xz -C /home/$USER/
4056
sudo ln -s /home/$USER/arduino-1.8.19/arduino /usr/bin/arduino
4157
sudo apt-get update
@@ -46,15 +62,6 @@ jobs:
4662
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
4763
brew install arduino --cask
4864
49-
- name: Checkout
50-
uses: actions/checkout@v2
51-
52-
# Node 14 matches the version of Node used by VS Code when this was
53-
# written, but it should be updated when VS Code updates its Node version.
54-
- name: Use Node 14.x
55-
uses: actions/setup-node@v2
56-
with:
57-
node-version: 14.x
5865
# Windows agents already have gulp installed.
5966
- name: Install gulp
6067
if: ${{ matrix.os != 'windows-latest' }}

azure-pipelines.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ steps:
6161
- script: curl -LO https://downloads.arduino.cc/arduino-1.8.19-windows.zip
6262
displayName: Download Arduino IDE
6363
- script: >-
64-
node --eval "process.exit(require('crypto').createHash('sha256').update(
65-
require('fs').readFileSync('arduino-1.8.19-windows.zip')).digest('hex')
66-
== 'c704a821089eab2588f1deae775916219b1517febd1dd574ff29958dca873945'
67-
? 0 : 1)"
64+
node build/checkHash.js arduino-1.8.19-windows.zip
65+
c704a821089eab2588f1deae775916219b1517febd1dd574ff29958dca873945
6866
displayName: Verify Arduino IDE
6967
- task: ExtractFiles@1
7068
displayName: Extract Arduino IDE

build/checkHash.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
// Usage
5+
// $ node checkHash.js myfile.zip c704...3945
6+
// Returns with an exit code of zero if and only if the SHA-256 hash of the
7+
// given file matches the expected hash.
8+
9+
const path = process.argv[2];
10+
const expected = process.argv[3];
11+
const data = require('fs').readFileSync(path);
12+
const hash = require('crypto').createHash('sha256').update(data).digest('hex');
13+
if (hash !== expected) {
14+
console.error(
15+
`Expected SHA-256 of "${path}" to be ${expected} but found ${hash}.`);
16+
process.exit(1);
17+
}

0 commit comments

Comments
 (0)