Update Build Action #44
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: Build and Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version' | ||
required: true | ||
default: '1.0.0' | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build Docker image | ||
run: docker build . -t my-application | ||
- name: Create Docker container without running it | ||
run: docker create --name app_build my-application | ||
- name: Copy build artifacts from Docker container | ||
run: | | ||
docker cp app_build:/usr/src/app/dist ./dist | ||
- name: Upload dist as artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: dist-artifact | ||
path: ./dist | ||
package: | ||
needs: build | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Download dist artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: dist-artifact | ||
path: ./dist | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.19.1 | ||
cache: 'npm' | ||
- name: Install pkg globally | ||
run: npm install -g pkg | ||
- name: Set PKG_TARGET environment variable and build executable | ||
run: | | ||
PKG_TARGET="" | ||
FILE_NAME="my-application-${{ matrix.os }}-${{ github.event.inputs.version }}" | ||
if [ "${{ runner.os }}" == "Windows" ]; then | ||
PKG_TARGET="node18-win-x64" | ||
FILE_NAME+=".exe" | ||
elif [ "${{ runner.os }}" == "macOS" ]; then | ||
PKG_TARGET="node18-macos-x64" | ||
else | ||
PKG_TARGET="node18-linux-x64" | ||
fi | ||
pkg -t $PKG_TARGET ./dist/main.js --output ./dist/$FILE_NAME | ||
echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV | ||
shell: bash | ||
- name: List contents of the dist directory | ||
run: ls -la ./dist/ | ||
- name: Upload executable as artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{ runner.os }}-exe | ||
path: ./dist/${{ env.FILE_NAME }} | ||
create_release: | ||
needs: package | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
steps: | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.event.inputs.version }} | ||
release_name: Release ${{ github.event.inputs.version }} | ||
draft: false | ||
prerelease: false | ||
upload_assets: | ||
needs: [create_release, package] | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Download dist artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: ${{ runner.os }}-exe | ||
path: ./dist | ||
- name: Upload Release Asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.YOUR_PERSONAL_ACCESS_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.create_release.outputs.upload_url }} | ||
asset_path: ./dist/my-application-${{ matrix.os }}-${{ github.event.inputs.version }}${{ runner.os == 'Windows' && '.exe' || '' }} | ||
asset_name: my-application-${{ matrix.os }}-${{ github.event.inputs.version }}${{ runner.os == 'Windows' && '.exe' || '' }} | ||
asset_content_type: application/octet-stream | ||