node-versions/.github/workflows/build-node-packages.yml

172 lines
5.2 KiB
YAML
Raw Normal View History

2020-08-24 08:10:43 +00:00
name: Generate Node.js package
2020-08-19 10:38:27 +00:00
on:
workflow_dispatch:
inputs:
VERSION:
2020-08-24 08:10:43 +00:00
description: 'Node.js version to build and upload'
2020-08-19 10:38:27 +00:00
required: true
default: '14.2.0'
PUBLISH_RELEASES:
description: 'Whether to publish releases'
required: true
default: 'false'
env:
VERSION: ${{ github.event.inputs.VERSION }}
jobs:
build_node:
2020-08-24 08:10:43 +00:00
name: Build Node.js ${{ github.event.inputs.VERSION }} [${{ matrix.platform }}]
2020-08-19 10:38:27 +00:00
runs-on: ubuntu-latest
2020-08-24 08:10:43 +00:00
env:
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION }}-${{ matrix.platform }}-x64
2020-08-19 10:38:27 +00:00
strategy:
fail-fast: false
matrix:
platform: [linux, darwin, win32]
steps:
- uses: actions/checkout@v2
with:
submodules: true
2020-08-24 08:10:43 +00:00
- name: Build Node.js ${{ env.VERSION }}
shell: pwsh
2020-08-19 10:38:27 +00:00
run: |
./builders/build-node.ps1 -Version $env:VERSION `
2020-08-24 08:10:43 +00:00
-Platform ${{ matrix.platform }}
2020-08-19 10:38:27 +00:00
- name: Publish artifact
uses: actions/upload-artifact@v2
with:
2020-08-24 08:10:43 +00:00
name: ${{ env.ARTIFACT_NAME }}
path: ${{ runner.temp }}/artifact
2020-08-19 10:38:27 +00:00
test_node:
2020-08-24 08:10:43 +00:00
name: Test Node.js ${{ github.event.inputs.VERSION }} [${{ matrix.platform }}]
2020-08-19 10:38:27 +00:00
needs: build_node
2020-08-24 08:10:43 +00:00
runs-on: ${{ matrix.os }}
defaults:
run:
shell: pwsh
env:
ARTIFACT_NAME: node-${{ github.event.inputs.VERSION }}-${{ matrix.platform }}-x64
2020-08-19 10:38:27 +00:00
strategy:
fail-fast: false
matrix:
include:
2020-08-24 08:10:43 +00:00
- os: ubuntu-latest
2020-08-19 10:38:27 +00:00
platform: linux
2020-08-24 08:10:43 +00:00
- os: macos-latest
2020-08-19 10:38:27 +00:00
platform: darwin
2020-08-24 08:10:43 +00:00
- os: windows-latest
2020-08-19 10:38:27 +00:00
platform: win32
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Fully cleanup the toolcache directory before testing
2020-08-24 08:10:43 +00:00
run: ./helpers/clean-toolcache.ps1 -ToolName "node"
2020-08-19 10:38:27 +00:00
- name: Download artifact
uses: actions/download-artifact@v2
with:
path: ${{ runner.temp }}
- name: Extract files
run: |
if ('${{ matrix.platform }}' -eq 'win32') {
2020-08-24 08:10:43 +00:00
$artifactName = "${{ env.ARTIFACT_NAME }}.7z"
2020-08-19 10:38:27 +00:00
7z.exe x "$artifactName" -y | Out-Null
} else {
2020-08-24 08:10:43 +00:00
$artifactName = "${{ env.ARTIFACT_NAME }}.tar.gz"
2020-08-19 10:38:27 +00:00
tar -xzf $artifactName
}
2020-08-24 08:10:43 +00:00
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
2020-08-19 10:38:27 +00:00
- name: Apply build artifact to the local machine
run: |
if ('${{ matrix.platform }}' -eq 'win32') { powershell ./setup.ps1 } else { sh ./setup.sh }
2020-08-24 08:10:43 +00:00
working-directory: ${{ runner.temp }}/${{ env.ARTIFACT_NAME }}
2020-08-19 10:38:27 +00:00
2020-08-24 08:10:43 +00:00
- name: Setup Node.js ${{ env.VERSION }}
2020-08-19 10:38:27 +00:00
uses: actions/setup-node@v2.1.1
with:
node-version: ${{ env.VERSION }}
- name: Wait for the logs
run: |
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 "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"
2020-08-24 08:10:43 +00:00
for ($i = 0; $i -lt 200; $i++) { Get-Random }
2020-08-19 10:38:27 +00:00
- name: Run tests
run: |
Install-Module Pester -Force -Scope CurrentUser -RequiredVersion 4.10.1
Import-Module Pester
$pesterParams = @{
Path="./Node.Tests.ps1";
Parameters=@{
Version="$env:VERSION";
}
}
2020-08-24 08:10:43 +00:00
Invoke-Pester -Script $pesterParams -EnableExit
2020-08-19 10:38:27 +00:00
working-directory: ./tests
publish_release:
name: Publish release
if: github.event.inputs.PUBLISH_RELEASES == 'true'
needs: test_node
runs-on: ubuntu-latest
steps:
2020-08-24 08:10:43 +00:00
- uses: actions/download-artifact@v2
2020-08-19 10:38:27 +00:00
- name: Publish Release ${{ env.VERSION }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}-${{ github.run_id }}
release_name: ${{ env.VERSION }}
body: |
2020-08-24 08:10:43 +00:00
Node.js ${{ env.VERSION }}
2020-08-19 10:38:27 +00:00
2020-08-24 08:10:43 +00:00
- name: Upload release assets
uses: actions/github-script@v2
2020-08-19 10:38:27 +00:00
with:
2020-08-24 08:10:43 +00:00
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
for (let artifactDir of fs.readdirSync('.')) {
let artifactName = fs.readdirSync(`${artifactDir}`)[0];
console.log(`Upload ${artifactName} asset`);
github.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.create_release.outputs.id }},
name: artifactName,
data: fs.readFileSync(`./${artifactDir}/${artifactName}`)
});
}
2020-08-19 10:38:27 +00:00
2020-08-24 08:10:43 +00:00
trigger_pr:
name: Trigger "Create Pull Request" workflow
needs: publish_release
2020-08-19 10:38:27 +00:00
runs-on: ubuntu-latest
steps:
- name: Trigger "Create Pull Request" workflow
2020-08-24 08:10:43 +00:00
uses: actions/github-script@v3
2020-08-19 10:38:27 +00:00
with:
github-token: ${{ secrets.PERSONAL_TOKEN }}
script: |
2020-08-24 08:10:43 +00:00
github.actions.createWorkflowDispatch({
2020-08-19 10:38:27 +00:00
owner: context.repo.owner,
repo: context.repo.repo,
2020-08-24 08:10:43 +00:00
workflow_id: 'create-pr.yml',
ref: 'main'
2020-08-19 10:38:27 +00:00
});