Node.js Package #127
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
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Node.js Package | |
on: | |
# release: | |
# types: [created] | |
workflow_dispatch: | |
jobs: | |
build-x86: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
deployments: write | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Required due to the way Git works, without it github-action-get-previous-tag won't be able to find any or the correct tags | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
registry-url: https://npm.pkg.github.com/ | |
- uses: mmomtchev/setup-swig@v3 | |
with: | |
branch: jse | |
- run: swig -version | |
# build x86_64 version, test, pack, package and native module | |
- run: npm i -g node-pre-gyp-github @mapbox/node-pre-gyp | |
- name: hack source | |
run: > | |
THEBIN="$(which node-pre-gyp-github)" | |
THEFILE="$(dirname $THEBIN)../index.js" | |
sed -i 's/{data}/data/g' $THEFILE && cat $THEFILE | |
- run: npm i --ignore-scripts | |
- run: node-pre-gyp rebuild | |
- run: npm run test | |
- run: node-pre-gyp package | |
- run: echo "PACKAGE_VERSION=$(jq -r -c .version < package.json)" >> $GITHUB_ENV | |
- name: Create Release | |
uses: comnoco/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.PACKAGE_VERSION }} | |
release_name: v${{ env.PACKAGE_VERSION }} | |
body: "@${{ github.repository }} ${{ env.PACKAGE_VERSION }}" | |
draft: false | |
prerelease: false | |
- run: NODE_PRE_GYP_GITHUB_TOKEN=$NODE_AUTH_TOKEN node-pre-gyp-github publish --release | |
- run: rm dist/pjsua2.node | |
- run: npm pack | |
- run: npm publish | |
start-arm64: | |
timeout-minutes: 5 # normally it only takes 1-2 minutes | |
needs: | |
- build-x86 | |
name: Start self-hosted EC2 runner | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: read | |
id-token: write | |
steps: | |
- name: Configure AWS credentials | |
id: creds | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ vars.AWS_REGION }} | |
role-to-assume: ${{ vars.ASSUME_ROLE_ARN }} | |
output-credentials: true | |
- name: Start EC2 runner | |
id: start-ec2-runner | |
uses: SemiConscious/[email protected] | |
with: | |
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
aws_access_key_id: ${{ steps.creds.outputs.aws-access-key-id }} | |
aws_secret_access_key: ${{ steps.creds.outputs.aws-secret-access-key }} | |
aws_session_token: ${{ steps.creds.outputs.aws-session-token }} | |
aws_region: ${{ vars.AWS_REGION }} | |
ec2_subnet_id: ${{ vars.SUBNET_ID }} | |
ec2_security_group_id: ${{ vars.SECURITY_GROUP_ID }} | |
ec2_instance_type: t4g.large | |
ec2_ami_id: ami-0c29a2c5cf69b5a9c # arm64 ubuntu 22.04 | |
ec2_instance_ttl: 40 # Optional (default is 60 minutes) | |
ec2_spot_instance_strategy: BestEffort # Other options are: None, SpotOnly, BestEffort, MaxPerformance | |
ec2_instance_tags: > # Required for IAM role resource permission scoping | |
[ | |
{"Key": "Owner", "Value": "runner-user"} | |
] | |
# Job that runs on the self-hosted runner | |
build-arm64: | |
timeout-minutes: 15 | |
needs: | |
- start-arm64 | |
runs-on: ${{ github.run_id }} | |
permissions: | |
contents: write | |
packages: write | |
deployments: write | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
steps: | |
- run: env | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
registry-url: https://npm.pkg.github.com/ | |
- run: apt-get update | |
- run: apt-get install -y libpcre2-dev autotools-dev autoconf libtool-bin g++ make bison uuid-dev | |
- run: npm i -g node-gyp node-addon-api | |
- uses: mmomtchev/setup-swig@v3 | |
with: | |
branch: jse | |
- run: swig -version | |
# build native version, test, pack, package and native module | |
- run: npm i -g node-pre-gyp-github | |
- run: npm i --ignore-scripts | |
- run: ./node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp rebuild package | |
- run: npm run test | |
- run: NODE_PRE_GYP_GITHUB_TOKEN=$NODE_AUTH_TOKEN node-pre-gyp-github publish --release |