Created
October 25, 2019 18:45
-
-
Save youhide/121750fc4878801ea8e908080b535beb to your computer and use it in GitHub Desktop.
GitHub Actions - Build for Windows, MacOS, Linux and release on tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Node CI | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
upload-release: | |
runs-on: ubuntu-18.04 | |
needs: [build-macos, build-linux, build-windows] | |
steps: | |
- uses: actions/checkout@v1 | |
- name: create release | |
id: create_release | |
uses: actions/create-release@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: false | |
prerelease: false | |
- name: download artifacts | |
uses: actions/download-artifact@v1 | |
with: | |
name: uploads | |
- name: upload macos | |
id: upload-macos | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./uploads/macos.zip | |
asset_name: macos.zip | |
asset_content_type: application/zip | |
- name: upload linux | |
id: upload-linux | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./uploads/linux.zip | |
asset_name: linux.zip | |
asset_content_type: application/zip | |
- name: upload windows | |
id: upload-windows | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./uploads/windows.zip | |
asset_name: windows.zip | |
asset_content_type: application/zip | |
build-macos: | |
runs-on: macOS-10.14 | |
strategy: | |
matrix: | |
node-version: [12.x] | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: npm install, build, and test | |
run: | | |
npm ci | |
npm test | |
- name: npm run build | |
run: | | |
npm run build | |
- name: zip macos artifact | |
run: | | |
zip -r macos out | |
- name: upload macos artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: uploads | |
path: macos.zip | |
build-linux: | |
runs-on: ubuntu-18.04 | |
strategy: | |
matrix: | |
node-version: [12.x] | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: npm install, build, and test | |
run: | | |
npm ci | |
npm test | |
- name: npm run build | |
run: | | |
npm run build | |
- name: zip linux artifact | |
run: | | |
zip -r linux out | |
- name: upload linux artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: uploads | |
path: linux.zip | |
build-windows: | |
runs-on: windows-2019 | |
strategy: | |
matrix: | |
node-version: [12.x] | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: npm install, build, and test | |
run: | | |
npm ci | |
npm test | |
- name: npm run build | |
run: | | |
npm run build | |
- name: zip win artifact | |
run: | | |
powershell Compress-Archive out windows.zip | |
- name: upload windows artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: uploads | |
path: windows.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@youhide That is very helpful! A small suggestion: replace the runner names to "ubuntu-latest", "macos-latest" and "windows-latest". I guess people will eventually want to fix the version in their pipelines, but for someone who just wants to get started the latest is the safest option.