Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): modify the build cli ci #1480

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 91 additions & 71 deletions .github/workflows/build_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,112 @@ name: Build MQTTX CLI packages
on:
pull_request:
paths:
- 'appscli/**'
- 'apps/cli/**'
release:
types:
- published

jobs:
build_packages:
runs-on: ubuntu-20.04
build_cli_packages:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.14
node-version: '18.17'

- name: build
run: |
cd cli
yarn && yarn build
npm install -g pkg
pkg package.json
- name: use pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- uses: actions/upload-artifact@v2
- name: Cache pnpm modules
uses: actions/cache@v3
with:
name: cli
path: cli/release
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-

- name: Install dependencies
run: pnpm install

- name: upload release asset
if: github.event_name == 'release'
- name: Install pkg globally using pnpm
run: pnpm add -g pkg

- name: Package application
run: |
cd cli/release
for var in $(ls); do
$GITHUB_WORKSPACE/.github/workflows/upload_github_release_asset.sh \
owner=${{ github.repository_owner }} \
repo=mqttx \
tag=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g") \
filename=$var \
github_api_token=$(echo ${{ secrets.GITHUB_TOKEN }})
done

publish_docker:
if: github.event_name == 'release'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: docker meta
id: meta
uses: docker/metadata-action@v4
pnpm run build:cli

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
images: emqx/mqttx-cli
flavor: |
latest=${{ !github.event.release.prerelease }}
tags: |
type=ref,event=tag
name: mqttx-cli
path: apps/cli/release

- name: set up qemu
uses: docker/setup-qemu-action@v2
# - name: upload release asset
# if: github.event_name == 'release'
# run: |
# cd cli/release
# for var in $(ls); do
# $GITHUB_WORKSPACE/.github/workflows/upload_github_release_asset.sh \
# owner=${{ github.repository_owner }} \
# repo=mqttx \
# tag=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g") \
# filename=$var \
# github_api_token=$(echo ${{ secrets.GITHUB_TOKEN }})
# done

- name: set up docker buildx
uses: docker/setup-buildx-action@v2
# publish_docker:
# if: github.event_name == 'release'
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v3
# - name: docker meta
# id: meta
# uses: docker/metadata-action@v4
# with:
# images: emqx/mqttx-cli
# flavor: |
# latest=${{ !github.event.release.prerelease }}
# tags: |
# type=ref,event=tag

- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# - name: set up qemu
# uses: docker/setup-qemu-action@v2

- name: build and push
uses: docker/build-push-action@v3
with:
context: ./cli
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}

publish_npm:
if: github.event_name == 'release' && !github.event.release.prerelease
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.14
registry-url: 'https://registry.npmjs.org'
- name: build
run: |
cd cli
yarn && yarn build && yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: set up docker buildx
# uses: docker/setup-buildx-action@v2

# - name: login to docker hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_HUB_USER }}
# password: ${{ secrets.DOCKER_HUB_TOKEN }}

# - name: build and push
# uses: docker/build-push-action@v3
# with:
# context: ./cli
# push: true
# platforms: linux/amd64,linux/arm64
# tags: ${{ steps.meta.outputs.tags }}

# publish_npm:
# if: github.event_name == 'release' && !github.event.release.prerelease
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 16.14
# registry-url: 'https://registry.npmjs.org'
# - name: build
# run: |
# cd cli
# yarn && yarn build && yarn publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- published

jobs:
build:
build_desktop_packages:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"scripts": {
"dev": "tsc -w",
"build": "tsc && pkg ."
"build": "tsc && pkg . -o ./release/mqttx-cli"
},
"main": "./dist/src/index.js",
"bin": {
Expand Down