Skip to content

Commit

Permalink
Add scheduled builds (#392)
Browse files Browse the repository at this point in the history
Refactor build workflows to allow reuse through workflow calls, and to make it easier to define different behaviour for different triggers.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
  • Loading branch information
bestbeforetoday committed Mar 2, 2023
1 parent e9c9eb7 commit 385efa8
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 93 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Pull request

on:
pull_request:
branches:
- main
- release-2.5
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
uses: ./.github/workflows/test.yaml

pull-request:
needs: test
name: Pull request success
runs-on: ubuntu-latest
steps:
- run: true
15 changes: 15 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Push

on:
push:
branches:
- main
- release-2.5
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/test.yaml
90 changes: 90 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Release

on:
create:
tags:
- "v2.*"
workflow_dispatch:

env:
CHAINCODE_CONTAINER_NODE_VER: 18
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}

jobs:
test:
uses: ./.github/workflows/test.yaml

publishnpm:
runs-on: ubuntu-20.04
needs: test
steps:
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v3
with:
name: node-tgzs
path: build/
- run: |
set -xev
ls -lart build/
cd build
find . -type f -name 'fabric-*.tgz' -exec npm publish {} \;
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publishdocker:
runs-on: ubuntu-20.04
needs: test
permissions:
contents: read
packages: write

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v3

- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
- name: Build and push ${{ matrix.COMPONENT }} Image
id: push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
file: docker/fabric-nodeenv/Dockerfile
context: docker/fabric-nodeenv
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}
15 changes: 15 additions & 0 deletions .github/workflows/schedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Scheduled build

on:
schedule:
- cron: "5 2 * * *"
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/test.yaml
with:
checkout-ref: ${{ matrix.checkout-ref }}
109 changes: 16 additions & 93 deletions .github/workflows/build.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: fabric-chaincode-node-build
name: Test

on:
push:
branches:
- main
- release-2.5
pull_request:
branches:
- main
- release-2.5
create:
tags:
- "v2.*"
workflow_dispatch:

env:
CHAINCODE_CONTAINER_NODE_VER: 18
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}
workflow_call:
inputs:
checkout-ref:
default: ''
required: false
type: string

jobs:
setup:
Expand All @@ -30,6 +20,8 @@ jobs:
BUILD_DATE: ${{ steps.builddata.outputs.BUILD_DATE }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: actions/setup-node@v3
with:
node-version: '18.x'
Expand Down Expand Up @@ -62,6 +54,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -101,12 +95,14 @@ jobs:

fvtest:
runs-on: ubuntu-20.04
needs: [build]
needs: build
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -165,6 +161,8 @@ jobs:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand All @@ -181,78 +179,3 @@ jobs:
mkdir -p audit && cd audit && npm init -y
npm install --registry http://localhost:4873 fabric-shim fabric-shim-api fabric-contract-api --save
npm audit --audit-level=moderate
publishnpm:
runs-on: ubuntu-20.04
needs: [build,fvtest,src_audit]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v3
with:
name: node-tgzs
path: build/
- run: |
set -xev
ls -lart build/
cd build
find . -type f -name 'fabric-*.tgz' -exec npm publish {} \;
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publishdocker:
runs-on: ubuntu-20.04
needs: [setup,build,fvtest,src_audit]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v3

- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
- name: Build and push ${{ matrix.COMPONENT }} Image
id: push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
file: docker/fabric-nodeenv/Dockerfile
context: docker/fabric-nodeenv
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}

0 comments on commit 385efa8

Please sign in to comment.