diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 25c2ebb1..26d18552 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,41 +2,36 @@ name: Build and Push Docker Images on: push: - branches: ["main"] - workflow_dispatch: + branches: + - 'main' + tags: + - 'v*' + pull_request: + branches: + - 'main' jobs: - paths-filter: - runs-on: ubuntu-latest - outputs: - frontend: ${{ steps.filter.outputs.frontend }} - api: ${{ steps.filter.outputs.api }} - widget: ${{ steps.filter.outputs.widget }} - nlu: ${{ steps.filter.outputs.nlu }} - steps: - - uses: actions/checkout@v4 - - name: Filter paths - id: filter - uses: dorny/paths-filter@v3 - with: - filters: | - frontend: - - 'frontend/**' - api: - - 'api/**' - widget: - - 'widget/**' - nlu: - - 'nlu/**' - build-and-push: runs-on: ubuntu-latest - needs: - - paths-filter steps: - name: Check out repository code uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + hexastack/hexabot-ui + hexastack/hexabot-api + hexastack/hexabot-base + hexastack/hexabot-nlu + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -44,6 +39,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub + if: github.event_name != 'pull_request' id: docker_login uses: docker/login-action@v2 with: @@ -51,44 +47,44 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Frontend Docker image - if: ${{ needs.paths-filter.outputs.frontend == 'true' }} uses: docker/build-push-action@v6 with: context: ./ + target: production file: ./frontend/Dockerfile platforms: linux/amd64,linux/arm64 - push: true - target: production - tags: hexastack/hexabot-ui:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - name: Build and push API Docker image - if: ${{ needs.paths-filter.outputs.api == 'true' }} uses: docker/build-push-action@v6 with: context: ./api/ target: production file: ./api/Dockerfile platforms: linux/amd64,linux/arm64 - push: true - tags: hexastack/hexabot-api:latest - - - name: Build and push Widget Docker image - if: ${{ needs.paths-filter.outputs.widget == 'true' }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Build and push Base Docker base image uses: docker/build-push-action@v6 with: - context: ./widget/ - file: ./widget/Dockerfile - platforms: linux/amd64,linux/arm64 + context: ./api/ target: production - push: true - tags: hexastack/hexabot-widget:latest + file: ./api/Dockerfile.base + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - name: Build and push NLU Docker image - if: ${{ needs.paths-filter.outputs.nlu == 'true' }} uses: docker/build-push-action@v6 with: context: ./nlu/ file: ./nlu/Dockerfile platforms: linux/amd64,linux/arm64 - push: true - tags: hexastack/hexabot-nlu:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/hexabot-npm.yml b/.github/workflows/hexabot-npm.yml new file mode 100644 index 00000000..7860372a --- /dev/null +++ b/.github/workflows/hexabot-npm.yml @@ -0,0 +1,63 @@ +name: Publish Hexabot (API Typescript) NPM Package + +on: + push: + tags: + - 'v*' + workflow_dispatch: # Allow manual trigger + +jobs: + publish-package: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' # Ensure it matches your project requirements + cache: 'npm' + + - name: Navigate to API Folder + run: cd api/ + + - name: Install dependencies + run: npm ci + + - name: Build the package + run: npm run build + + - name: Determine release type + id: determine-release + run: | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then + echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV + if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then + echo "release=minor" >> $GITHUB_ENV + elif [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "release=patch" >> $GITHUB_ENV + else + echo "release=none" >> $GITHUB_ENV + fi + else + echo "release=none" >> $GITHUB_ENV + fi + + - name: Login to npm + if: env.release != 'none' + uses: actions/setup-node@v3 + with: + registry-url: 'https://registry.npmjs.org/' + node-version: '18' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish to npm + if: env.release != 'none' + run: | + if [[ "$release" == "patch" ]]; then + npm run release:patch + elif [[ "$release" == "minor" ]]; then + npm run release:minor + fi diff --git a/.github/workflows/widget-npm.yml b/.github/workflows/widget-npm.yml new file mode 100644 index 00000000..c3765784 --- /dev/null +++ b/.github/workflows/widget-npm.yml @@ -0,0 +1,58 @@ +name: Publish Hexabot Widget NPM Package + +on: + push: + tags: + - 'v*' + workflow_dispatch: # Allow manual trigger + +jobs: + publish-package: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' # Ensure it matches your project requirements + cache: 'npm' + + - name: Navigate to Widget Folder + run: cd widget/ + + - name: Install dependencies + run: npm ci + + - name: Build the package + run: npm run build + + - name: Determine release type + id: determine-release + run: | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then + echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV + if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then + echo "release=minor" >> $GITHUB_ENV + elif [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "release=patch" >> $GITHUB_ENV + else + echo "release=none" >> $GITHUB_ENV + fi + else + echo "release=none" >> $GITHUB_ENV + fi + + - name: Login to npm + if: env.release != 'none' + uses: actions/setup-node@v3 + with: + registry-url: 'https://registry.npmjs.org/' + node-version: '18' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish to npm + if: env.release != 'none' + run: npm publish diff --git a/api/package.json b/api/package.json index 41e88d9c..720bd778 100644 --- a/api/package.json +++ b/api/package.json @@ -39,13 +39,7 @@ "typecheck": "tsc --noEmit", "reset": "npm install && npm run containers:restart", "reset:hard": "npm clean-install && npm run containers:rebuild", - "migrate": "npx ts-migrate-mongoose --config-path ./migrations/config/migrate.ts", - "docker:build-base": "docker build --pull --rm -f Dockerfile.base -t hexabot-base:latest .", - "docker:tag-base": "docker tag hexabot-base:latest hexastack/hexabot-base:latest", - "docker:push-base": "docker push hexastack/hexabot-base:latest", - "docker:release-base": "npm run docker:build-base && npm run docker:tag-base && npm run docker:push-base", - "npm:release": "npm version patch && npm publish", - "release": "npm run build && npm run npm:release && npm run docker:release-base" + "migrate": "npx ts-migrate-mongoose --config-path ./migrations/config/migrate.ts" }, "dependencies": { "@nestjs-modules/mailer": "^1.11.2", @@ -178,4 +172,4 @@ "@/(.*)": "/$1" } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index bb74c01a..5b22bec6 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "scripts": { "prepare": "husky install", "dev:frontend": "npm run dev --workspace=frontend", - "dev:widget": "npm run dev --workspace=widget" + "dev:widget": "npm run dev --workspace=widget", + "release:api:patch": "npm version patch --workspace=api --workspace=frontend --workspace=widget && git push origin main --tags", + "release:api:minor": "npm version minor --workspace=api --workspace=frontend --workspace=widget && git push origin main --tags" }, "devDependencies": { "@commitlint/cli": "^19.3.0", diff --git a/widget/package.json b/widget/package.json index 8fac6ff7..63e55560 100644 --- a/widget/package.json +++ b/widget/package.json @@ -14,8 +14,7 @@ "lint:fix": "eslint . --ext ts,tsx --fix", "preview": "vite preview", "serve": "npx http-server ./dist/", - "typecheck": "tsc --noEmit", - "release": "npm run build && npm version patch && npm publish" + "typecheck": "tsc --noEmit" }, "dependencies": { "@types/emoji-js": "^3.5.2",