ci(workflow): add cache to workflows using actions/setup-node #70
215
.github/workflows/build-node-packages.yml
vendored
215
.github/workflows/build-node-packages.yml
vendored
@@ -3,20 +3,20 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
VERSION:
|
VERSION:
|
||||||
description: 'Node.js version to build and upload'
|
description: "Node.js version to build and upload"
|
||||||
required: true
|
required: true
|
||||||
default: '14.2.0'
|
default: "14.2.0"
|
||||||
PUBLISH_RELEASES:
|
PUBLISH_RELEASES:
|
||||||
description: 'Whether to publish releases'
|
description: "Whether to publish releases"
|
||||||
required: true
|
required: true
|
||||||
default: 'false'
|
default: "false"
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- 'versions-manifest.json'
|
- "versions-manifest.json"
|
||||||
- 'LICENSE'
|
- "LICENSE"
|
||||||
- '**.md'
|
- "**.md"
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- "main"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ github.event.inputs.VERSION || '14.0.0' }}
|
VERSION: ${{ github.event.inputs.VERSION || '14.0.0' }}
|
||||||
@@ -28,92 +28,93 @@ jobs:
|
|||||||
build_node:
|
build_node:
|
||||||
name: Build Node.js ${{ github.event.inputs.VERSION || '14.0.0' }} [${{ matrix.platform }}]
|
name: Build Node.js ${{ github.event.inputs.VERSION || '14.0.0' }} [${{ matrix.platform }}]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION || '14.0.0' }}-${{ matrix.platform }}-x64
|
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION || '14.0.0' }}-${{ matrix.platform }}-x64
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
platform: [linux, darwin, win32]
|
platform: [linux, darwin, win32]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
- name: Build Node.js ${{ env.VERSION }}
|
- name: Build Node.js ${{ env.VERSION }}
|
||||||
run: |
|
run: |
|
||||||
./builders/build-node.ps1 -Version $env:VERSION `
|
./builders/build-node.ps1 -Version $env:VERSION `
|
||||||
-Platform ${{ matrix.platform }}
|
-Platform ${{ matrix.platform }}
|
||||||
|
|
||||||
- name: Publish artifact
|
- name: Publish artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: ${{ env.ARTIFACT_NAME }}
|
name: ${{ env.ARTIFACT_NAME }}
|
||||||
path: ${{ runner.temp }}/artifact
|
path: ${{ runner.temp }}/artifact
|
||||||
|
|
||||||
test_node:
|
test_node:
|
||||||
name: Test Node.js ${{ github.event.inputs.VERSION || '14.0.0' }} [${{ matrix.platform }}]
|
name: Test Node.js ${{ github.event.inputs.VERSION || '14.0.0' }} [${{ matrix.platform }}]
|
||||||
needs: build_node
|
needs: build_node
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION || '14.0.0' }}-${{ matrix.platform }}-x64
|
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION || '14.0.0' }}-${{ matrix.platform }}-x64
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
platform: linux
|
platform: linux
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
platform: darwin
|
platform: darwin
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
platform: win32
|
platform: win32
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
- name: Fully cleanup the toolcache directory before testing
|
- name: Fully cleanup the toolcache directory before testing
|
||||||
run: ./helpers/clean-toolcache.ps1 -ToolName "node"
|
run: ./helpers/clean-toolcache.ps1 -ToolName "node"
|
||||||
|
|
||||||
- name: Download artifact
|
- name: Download artifact
|
||||||
uses: actions/download-artifact@v2
|
uses: actions/download-artifact@v2
|
||||||
with:
|
with:
|
||||||
path: ${{ runner.temp }}
|
path: ${{ runner.temp }}
|
||||||
|
|
||||||
- name: Extract files
|
- name: Extract files
|
||||||
run: |
|
run: |
|
||||||
if ('${{ matrix.platform }}' -eq 'win32') {
|
if ('${{ matrix.platform }}' -eq 'win32') {
|
||||||
$artifactName = "${{ env.ARTIFACT_NAME }}.7z"
|
$artifactName = "${{ env.ARTIFACT_NAME }}.7z"
|
||||||
7z.exe x "$artifactName" -y | Out-Null
|
7z.exe x "$artifactName" -y | Out-Null
|
||||||
} else {
|
} else {
|
||||||
$artifactName = "${{ env.ARTIFACT_NAME }}.tar.gz"
|
$artifactName = "${{ env.ARTIFACT_NAME }}.tar.gz"
|
||||||
tar -xzf $artifactName
|
tar -xzf $artifactName
|
||||||
}
|
}
|
||||||
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
|
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
|
||||||
|
|
||||||
- name: Apply build artifact to the local machine
|
- name: Apply build artifact to the local machine
|
||||||
run: |
|
run: |
|
||||||
if ('${{ matrix.platform }}' -eq 'win32') { powershell ./setup.ps1 } else { sh ./setup.sh }
|
if ('${{ matrix.platform }}' -eq 'win32') { powershell ./setup.ps1 } else { sh ./setup.sh }
|
||||||
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
|
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
|
||||||
|
|
||||||
- name: Setup Node.js ${{ env.VERSION }}
|
- name: Setup Node.js ${{ env.VERSION }}
|
||||||
uses: actions/setup-node@v2.1.2
|
uses: actions/setup-node@v2.1.2
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.VERSION }}
|
node-version: ${{ env.VERSION }}
|
||||||
|
cache: npm
|
||||||
|
|
||||||
- name: Wait for the logs
|
- name: Wait for the logs
|
||||||
run: |
|
run: |
|
||||||
Write-Host "Fake step that do nothing"
|
Write-Host "Fake step that do nothing"
|
||||||
Write-Host "We need it because log of previous step 'Setup Node' is not available here yet."
|
Write-Host "We need it because log of previous step 'Setup Node' is not available here yet."
|
||||||
Write-Host "In testing step (Node.Tests.ps1) we analyze build log of 'Setup Node' task"
|
Write-Host "In testing step (Node.Tests.ps1) we analyze build log of 'Setup Node' task"
|
||||||
Write-Host "to determine if Node.js version was consumed from cache and was downloaded"
|
Write-Host "to determine if Node.js version was consumed from cache and was downloaded"
|
||||||
for ($i = 0; $i -lt 200; $i++) { Get-Random }
|
for ($i = 0; $i -lt 200; $i++) { Get-Random }
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
Install-Module Pester -Force -Scope CurrentUser
|
Install-Module Pester -Force -Scope CurrentUser
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Invoke-Pester -Script ./Node.Tests.ps1 -EnableExit
|
Invoke-Pester -Script ./Node.Tests.ps1 -EnableExit
|
||||||
working-directory: ./tests
|
working-directory: ./tests
|
||||||
|
|
||||||
publish_release:
|
publish_release:
|
||||||
name: Publish release
|
name: Publish release
|
||||||
@@ -121,52 +122,52 @@ jobs:
|
|||||||
needs: test_node
|
needs: test_node
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@v2
|
- uses: actions/download-artifact@v2
|
||||||
|
|
||||||
- name: Publish Release ${{ env.VERSION }}
|
- name: Publish Release ${{ env.VERSION }}
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ env.VERSION }}-${{ github.run_id }}
|
tag_name: ${{ env.VERSION }}-${{ github.run_id }}
|
||||||
release_name: ${{ env.VERSION }}
|
release_name: ${{ env.VERSION }}
|
||||||
body: |
|
body: |
|
||||||
Node.js ${{ env.VERSION }}
|
Node.js ${{ env.VERSION }}
|
||||||
|
|
||||||
- name: Upload release assets
|
- name: Upload release assets
|
||||||
uses: actions/github-script@v2
|
uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
for (let artifactDir of fs.readdirSync('.')) {
|
for (let artifactDir of fs.readdirSync('.')) {
|
||||||
let artifactName = fs.readdirSync(`${artifactDir}`)[0];
|
let artifactName = fs.readdirSync(`${artifactDir}`)[0];
|
||||||
|
|
||||||
console.log(`Upload ${artifactName} asset`);
|
console.log(`Upload ${artifactName} asset`);
|
||||||
github.repos.uploadReleaseAsset({
|
github.repos.uploadReleaseAsset({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
release_id: ${{ steps.create_release.outputs.id }},
|
release_id: ${{ steps.create_release.outputs.id }},
|
||||||
name: artifactName,
|
name: artifactName,
|
||||||
data: fs.readFileSync(`./${artifactDir}/${artifactName}`)
|
data: fs.readFileSync(`./${artifactDir}/${artifactName}`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_pr:
|
trigger_pr:
|
||||||
name: Trigger "Create Pull Request" workflow
|
name: Trigger "Create Pull Request" workflow
|
||||||
needs: publish_release
|
needs: publish_release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Trigger "Create Pull Request" workflow
|
- name: Trigger "Create Pull Request" workflow
|
||||||
uses: actions/github-script@v3
|
uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.PERSONAL_TOKEN }}
|
github-token: ${{ secrets.PERSONAL_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
github.actions.createWorkflowDispatch({
|
github.actions.createWorkflowDispatch({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
workflow_id: 'create-pr.yml',
|
workflow_id: 'create-pr.yml',
|
||||||
ref: 'main'
|
ref: 'main'
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user