From 4fda1fc5d50178b6321377aa7877d3e1fe4429fa Mon Sep 17 00:00:00 2001 From: Garris Date: Fri, 23 Feb 2024 15:54:38 -0800 Subject: [PATCH] Create test-build-pub-npm-dockerhub.yml --- .../test-build-pub-npm-dockerhub.yml | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/test-build-pub-npm-dockerhub.yml diff --git a/.github/workflows/test-build-pub-npm-dockerhub.yml b/.github/workflows/test-build-pub-npm-dockerhub.yml new file mode 100644 index 00000000..60bc7b68 --- /dev/null +++ b/.github/workflows/test-build-pub-npm-dockerhub.yml @@ -0,0 +1,99 @@ +name: Test build & publish npm + docker + +on: + workflow_dispatch: + workflow_call: + +permissions: + actions: write + checks: write + contents: write + pull-requests: write + packages: write + +env: + NODE_VERSION: 20 + +jobs: + reference-test: + name: reference-test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: Setup Node & Cache + uses: actions/setup-node@v4 + with: + cache: "npm" + cache-dependency-path: package-lock.json + + - name: Install + run: npm ci + + - name: "execute test" + run: npm run reference-test + + + npm-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: Setup Node & Cache + uses: actions/setup-node@v4 + with: + cache: "npm" + cache-dependency-path: package-lock.json + + - name: Setup npm + run: npm ci + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + build-and-push-docker-image: + runs-on: ubuntu-latest + + steps: + - name: ⇣ Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: 🏷️ Set Docker Image Tag + run: | + echo "PV=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: ⬢ Setup Node & Cache + uses: actions/setup-node@v4 + with: + cache: "npm" + cache-dependency-path: package-lock.json + + - name: ↧ Install + run: npm ci --verbose --foreground-scripts + + - name: 🚢 Build Docker Builder + run: | + npm run --verbose --foreground-scripts init-docker-builder + + - name: 🐳 Build & Push to Docker Hub + run: | + docker buildx build --push --platform linux/amd64,linux/arm64 -t backstopjs/backstopjs:$PV --build-arg BACKSTOPJS_VERSION=$PV docker