From 19ba730ec147a551d415a469b97aa359587a8284 Mon Sep 17 00:00:00 2001 From: Ch4s3r Date: Mon, 24 Jun 2024 23:31:27 +0200 Subject: [PATCH 1/2] feat: Add buildpacks for building docker image --- .github/workflows/docker.yml | 113 ---------------------------------- .github/workflows/release.yml | 34 +++++----- .github/workflows/testing.yml | 23 ++----- Dockerfile | 38 ------------ package.json | 8 ++- 5 files changed, 31 insertions(+), 185 deletions(-) delete mode 100644 .github/workflows/docker.yml delete mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index ffe21504..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,113 +0,0 @@ -name: Docker - -on: - push: - tags: - - "*" - workflow_dispatch: - -env: - REGISTRY_IMAGE: mergeability/mergeable - -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - # Failing to build - # - linux/arm/v6 - - linux/arm/v7 - - linux/arm64 - steps: - - name: Prepare - run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY_IMAGE }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - platforms: ${{ matrix.platform }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true - cache-from: type=gha,scope=build-${{ matrix.platform }} - cache-to: type=gha,mode=max,scope=build-${{ matrix.platform }} - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - - merge: - runs-on: ubuntu-latest - needs: - - build - steps: - - name: Download digests - uses: actions/download-artifact@v4 - with: - path: /tmp/digests - pattern: digests-* - merge-multiple: true - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY_IMAGE }} - tags: | - # minimal - type=semver,pattern={{version}} - # set latest tag for default branch - type=raw,value=latest,enable={{is_default_branch}} - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Create manifest list and push - working-directory: /tmp/digests - run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) - - - name: Inspect image - run: | - docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 00eacd9a..c7e029a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,26 +5,30 @@ on: branches: - master +env: + DOCKER_IMAGE_NAME: ch4s3r/mergeable + jobs: build: name: Release runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [20.11.1] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - name: Release + - name: Checkout + uses: actions/checkout@v4 + - name: Semantic Release + id: semantic + uses: cycjimmy/semantic-release-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + if: ${{ steps.semantic.outputs.new_release_version }} + - uses: buildpacks/github-actions/setup-pack@v5.7.2 + if: ${{ steps.semantic.outputs.new_release_version }} + - name: Build and publish docker image + if: ${{ steps.semantic.outputs.new_release_version }} + run: pack build ${{ env.DOCKER_IMAGE_NAME }} -t ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.semantic.outputs.new_release_version }} -t ${{ env.DOCKER_IMAGE_NAME }}:latest -B paketobuildpacks/builder-jammy-tiny -b docker.io/paketobuildpacks/nodejs --publish diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d6819bdc..b1fc0533 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -2,30 +2,19 @@ name: CI on: push: - branches: ['**'] + branches: [ "*" ] pull_request: - branches: ['**'] - -permissions: - contents: read + branches: [ "*" ] jobs: build: - name: Tests and Code Coverage runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [20.11.1] - steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} - - run: npm install + node-version: '20.x' + - run: npm ci - run: npm run build --if-present - - run: npm run test-coverage - env: - CI: true + - run: npm test diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 5201990c..00000000 --- a/Dockerfile +++ /dev/null @@ -1,38 +0,0 @@ -# syntax=docker/dockerfile:1 - -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/go/dockerfile-reference/ - -# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - -ARG NODE_VERSION=18 - -FROM node:${NODE_VERSION}-alpine - -# Use production node environment by default. -ENV NODE_ENV production - - -WORKDIR /usr/src/app - -# Download dependencies as a separate step to take advantage of Docker's caching. -# Leverage a cache mount to /root/.npm to speed up subsequent builds. -# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into -# into this layer. -RUN --mount=type=bind,source=package.json,target=package.json \ - --mount=type=bind,source=package-lock.json,target=package-lock.json \ - --mount=type=cache,target=/root/.npm \ - npm ci --omit=dev - -# Run the application as a non-root user. -USER node - -# Copy the rest of the source files into the image. -COPY . . - -# Expose the port that the application listens on. -EXPOSE 3000 - -# Run the application. -CMD npm start diff --git a/package.json b/package.json index f2b4a029..e43210e6 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "standard": "^16.0.3" }, "engines": { - "node": ">= 18.12.1" + "node": "^20" }, "standard": { "env": [ @@ -58,5 +58,9 @@ "collectCoverageFrom": [ "lib/**/*.js" ] - } + }, + "publishConfig": { + "access": "public" + }, + "private": false } From 794ff6e142ccddb5e866ef0b35f9496ec5b98c4e Mon Sep 17 00:00:00 2001 From: Ch4s3r Date: Mon, 24 Jun 2024 23:42:18 +0200 Subject: [PATCH 2/2] feat: my feature --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 9789c5ec..bb575d2d 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ module.exports = (robot, { getRouter }) => { } } + logger.init(robot.log) const mergeable = new Mergeable(process.env.NODE_ENV) mergeable.start(robot)