From 3c5ea2a745b32e79fe5dbfe739f4ab554774e2e8 Mon Sep 17 00:00:00 2001 From: Bob Steers Date: Fri, 24 Mar 2023 17:34:40 +0100 Subject: [PATCH] Switch to github actions --- .github/workflows/build.yml | 68 ++++++++++++++++++++++++++++ azure-pipelines.yml | 90 ------------------------------------- 2 files changed, 68 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 azure-pipelines.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..dd9d95c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,68 @@ +name: CI build + +on: + push: + branches: ["**"] + pull_request: + branches: [develop, edge] + +jobs: + build: + if: github.repository_owner == 'BrewBlox' + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Set tag variable + run: | + echo "TAG=$(echo "${{ github.ref_name }}" | tr '/' '-' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + echo "NPM_VERSION=$(node -pe "require('./package.json').version")" >> $GITHUB_ENV + + - name: Get image metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/brewblox/node-red + + - name: ghcr.io login + uses: docker/login-action@v2 + if: github.event_name != 'pull_request' + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: NPM login + if: github.event_name != 'pull_request' + run: | + npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_AUTH_TOKEN }} + + - run: yarn install + - run: yarn lint + - run: yarn test + - run: yarn build + + - name: Build Docker image + uses: docker/build-push-action@v4 + with: + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 + context: . + + - name: NPM publish + if: github.event_name != 'pull_request' + run: | + npm publish --tag ${{ env.TAG }} || npm dist-tag add node-red-contrib-brewblox@${{ env.NPM_VERSION }} ${{ env.TAG }} + + - name: NPM tag latest + if: github.event_name != 'pull_request' && github.ref_name == 'edge' + run: | + npm dist-tag add node-red-contrib-brewblox@${{ env.NPM_VERSION }} latest diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index a3914c1..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,90 +0,0 @@ -pool: - vmImage: "Ubuntu-20.04" - -trigger: - tags: - include: - - "*" - branches: - include: - - refs/heads/* - -pr: - branches: - include: - - "*" - -variables: - # Variables imported from brewblox group: - # DOCKER_USER - # DOCKER_PASSWORD - # NPM_TOKEN - - group: brewblox - - name: DOCKER_REPO - value: brewblox/node-red - - name: NPM_REPO - value: node-red-contrib-brewblox - -steps: - - task: NodeTool@0 - inputs: - versionSpec: "12.x" - displayName: "Install Node.js" - - - bash: | - BRANCH=$(echo $(Build.SourceBranch) | grep -oP "^refs/heads/\K.*") - TAG=$(echo $BRANCH | tr '/' '-' | tr '[:upper:]' '[:lower:]') - NPM_VERSION=$(node -pe "require('./package.json').version") - echo "##vso[task.setvariable variable=BRANCH]$BRANCH" - echo "##vso[task.setvariable variable=TAG]$TAG" - echo "##vso[task.setvariable variable=NPM_VERSION]$NPM_VERSION" - displayName: Export build variables - - - bash: | - yarn install - displayName: Install - - - bash: | - yarn lint - yarn test - displayName: Test - - - bash: | - yarn build - displayName: Build - - - bash: | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --use - docker buildx inspect --bootstrap - displayName: Prepare buildx - condition: and(succeeded(), variables.BRANCH) - - - bash: | - echo $(DOCKER_PASSWORD) | docker login -u $(DOCKER_USER) --password-stdin - displayName: Docker login - condition: and(succeeded(), variables.BRANCH) - - - bash: | - npm set //registry.npmjs.org/:_authToken $(NPM_TOKEN) - displayName: NPM login - condition: and(succeeded(), variables.BRANCH) - - - bash: >- - docker buildx build - --tag $(DOCKER_REPO):$(TAG) - --push - --platform linux/amd64,linux/arm/v7,linux/arm64/v8 - . - displayName: Docker build - condition: and(succeeded(), variables.BRANCH) - - - bash: | - npm publish --tag $(TAG) || npm dist-tag add $(NPM_REPO)@$(NPM_VERSION) $(TAG) - displayName: NPM publish - condition: and(succeeded(), variables.BRANCH) - - - bash: | - npm dist-tag add $(NPM_REPO)@$(NPM_VERSION) latest - displayName: NPM tag latest - condition: and(succeeded(), variables.BRANCH, eq(variables.BRANCH, 'edge'))