Skip to content

Workflow file for this run

on: push
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ".tool-versions"
cache: 'npm'
- name: Setup dependencies
run: npm ci
- name: Run Tests
run: npm run test
release:
name: Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
release_tag: ${{ steps.release-please.outputs.tag_name }}
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: google-github-actions/release-please-action@v4
id: release-please
with:
token: ${{ secrets.SOMLENG_PERSONAL_ACCESS_TOKEN }}
build-packages:
name: Build Packages
needs:
- release
runs-on: ${{ matrix.runs-on }}
if: ${{ needs.release.outputs.release_created }}
outputs:
package_name: ${{ steps.set-package-details.outputs.package_name }}
package_version: ${{ steps.set-package-details.outputs.package_version }}
strategy:
matrix:
os: ["linux"]
platform: [amd64, arm64]
include:
- os: linux
platform: amd64
runs-on: ubuntu-latest
- os: linux
platform: arm64
runs-on: ubuntu-latest
aws-runner: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ".tool-versions"
cache: 'npm'
- name: Set package details
id: set-package-details
run: |
npm ci
npm run build
package_name=$(npm pkg get name | xargs echo)
package_version=$(npm pkg get version | xargs echo)
full_package_name=$package_name-${{ matrix.os }}-${{ matrix.platform }}-v$package_version
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "full_package_name=$full_package_name" >> $GITHUB_OUTPUT
- name: Build packages natively
if: ${{ !matrix.aws-runner }}
run: |
npm run dist ${{ steps.set-package-details.outputs.full_package_name }}
- name: Set build parameters
if: ${{ matrix.aws-runner }}
id: set-build-parameters
run: |
echo "build-project=sms-gateway-${{ matrix.os }}-${{ matrix.platform }}" >> $GITHUB_OUTPUT
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
if: ${{ matrix.aws-runner }}
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-skip-session-tagging: true
role-duration-seconds: 3600
aws-region: ap-southeast-1
- name: Build packages on AWS
if: ${{ matrix.aws-runner }}
uses: aws-actions/aws-codebuild-run-build@v1
id: build-packages
with:
project-name: ${{ steps.set-build-parameters.outputs.build-project }}
buildspec-override: |
version: 0.2
phases:
install:
runtime-versions:
nodejs: 18.x
commands:
- n 21
build:
steps:
- name: Generate dist
id: generate_dist
run: |
npm ci
npm run build
npm run dist ${{ steps.set-package-details.outputs.full_package_name }}
artifacts:
name: ${{ github.sha }}
files:
- build/*
- name: Download Packages from S3
if : ${{ matrix.aws-runner }}
run: |
aws s3 cp s3://ci-artifacts.somleng.org/${{ steps.set-build-parameters.outputs.build-project }}/${{ github.sha }}/build/${{ steps.set-package-details.outputs.full_package_name }} build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-package-details.outputs.full_package_name }}
path: build/${{ steps.set-package-details.outputs.full_package_name }}
retention-days: 1
upload-packages:
name: Upload Packages
needs:
- build-packages
- release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ".tool-versions"
cache: 'npm'
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: build
pattern: ${{ needs.build-packages.outputs.package_name }}-*
merge-multiple: true
- name: Add assets to Github Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
linux_x64_pkg="${{ needs.build-packages.outputs.package_name }}-linux-x86_64-v${{ needs.build-packages.outputs.package_version }}.zip"
linux_aarch64_pkg="${{ needs.build-packages.outputs.package_name }}-linux-aarch64-v${{ needs.build-packages.outputs.package_version }}.zip"
cp build/${{ needs.build-packages.outputs.package_name }}-linux-amd64-v${{ needs.build-packages.outputs.package_version }} ${{ needs.build-packages.outputs.package_name }}
zip $linux_x64_pkg ${{ needs.build-packages.outputs.package_name }}
cp build/${{ needs.build-packages.outputs.package_name }}-linux-arm64-v${{ needs.build-packages.outputs.package_version }} ${{ needs.build-packages.outputs.package_name }}
zip $linux_aarch64_pkg ${{ needs.build-packages.outputs.package_name }}
gh release upload ${{ needs.release.outputs.release_tag }} $linux_x64_pkg
gh release upload ${{ needs.release.outputs.release_tag }} $linux_aarch64_pkg
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
- somleng/sms-gateway
- ghcr.io/somleng/sms-gateway
tags: |
# set latest tag for main branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{ needs.release.outputs.release_tag }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}