Skip to content

Commit 385efa8

Browse files
Add scheduled builds (#392)
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>
1 parent e9c9eb7 commit 385efa8

File tree

5 files changed

+162
-93
lines changed

5 files changed

+162
-93
lines changed

.github/workflows/pull_request.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Pull request
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
- release-2.5
11+
workflow_dispatch:
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
test:
19+
uses: ./.github/workflows/test.yaml
20+
21+
pull-request:
22+
needs: test
23+
name: Pull request success
24+
runs-on: ubuntu-latest
25+
steps:
26+
- run: true

.github/workflows/push.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Push
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- release-2.5
11+
workflow_dispatch:
12+
13+
jobs:
14+
test:
15+
uses: ./.github/workflows/test.yaml

.github/workflows/release.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Release
5+
6+
on:
7+
create:
8+
tags:
9+
- "v2.*"
10+
workflow_dispatch:
11+
12+
env:
13+
CHAINCODE_CONTAINER_NODE_VER: 18
14+
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}
15+
16+
jobs:
17+
test:
18+
uses: ./.github/workflows/test.yaml
19+
20+
publishnpm:
21+
runs-on: ubuntu-20.04
22+
needs: test
23+
steps:
24+
- uses: actions/setup-node@v3
25+
with:
26+
node-version: '18.x'
27+
registry-url: 'https://registry.npmjs.org'
28+
- uses: actions/download-artifact@v3
29+
with:
30+
name: node-tgzs
31+
path: build/
32+
- run: |
33+
set -xev
34+
ls -lart build/
35+
cd build
36+
find . -type f -name 'fabric-*.tgz' -exec npm publish {} \;
37+
env:
38+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
40+
publishdocker:
41+
runs-on: ubuntu-20.04
42+
needs: test
43+
permissions:
44+
contents: read
45+
packages: write
46+
47+
steps:
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v2
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v2
53+
with:
54+
buildkitd-flags: --debug
55+
config-inline: |
56+
[worker.oci]
57+
max-parallelism = 1
58+
59+
- name: Checkout
60+
uses: actions/checkout@v3
61+
62+
- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
63+
uses: docker/login-action@v2
64+
with:
65+
registry: ${{ env.DOCKER_REGISTRY }}
66+
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
67+
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
68+
69+
- name: Docker meta
70+
id: meta
71+
uses: docker/metadata-action@v4
72+
with:
73+
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
74+
tags: |
75+
type=semver,pattern={{version}}
76+
type=semver,pattern={{major}}.{{minor}}
77+
type=semver,pattern={{major}}.{{minor}}.{{patch}}
78+
79+
- name: Build and push ${{ matrix.COMPONENT }} Image
80+
id: push
81+
uses: docker/build-push-action@v3
82+
with:
83+
platforms: linux/amd64,linux/arm64
84+
file: docker/fabric-nodeenv/Dockerfile
85+
context: docker/fabric-nodeenv
86+
tags: ${{ steps.meta.outputs.tags }}
87+
push: ${{ github.event_name != 'pull_request' }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
build-args: |
90+
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}

.github/workflows/schedule.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright the Hyperledger Fabric contributors. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Scheduled build
5+
6+
on:
7+
schedule:
8+
- cron: "5 2 * * *"
9+
workflow_dispatch:
10+
11+
jobs:
12+
test:
13+
uses: ./.github/workflows/test.yaml
14+
with:
15+
checkout-ref: ${{ matrix.checkout-ref }}

.github/workflows/build.yaml renamed to .github/workflows/test.yaml

Lines changed: 16 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
# Copyright the Hyperledger Fabric contributors. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
name: fabric-chaincode-node-build
4+
name: Test
55

66
on:
7-
push:
8-
branches:
9-
- main
10-
- release-2.5
11-
pull_request:
12-
branches:
13-
- main
14-
- release-2.5
15-
create:
16-
tags:
17-
- "v2.*"
18-
workflow_dispatch:
19-
20-
env:
21-
CHAINCODE_CONTAINER_NODE_VER: 18
22-
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}
7+
workflow_call:
8+
inputs:
9+
checkout-ref:
10+
default: ''
11+
required: false
12+
type: string
2313

2414
jobs:
2515
setup:
@@ -30,6 +20,8 @@ jobs:
3020
BUILD_DATE: ${{ steps.builddata.outputs.BUILD_DATE }}
3121
steps:
3222
- uses: actions/checkout@v3
23+
with:
24+
ref: ${{ inputs.checkout-ref }}
3325
- uses: actions/setup-node@v3
3426
with:
3527
node-version: '18.x'
@@ -62,6 +54,8 @@ jobs:
6254

6355
steps:
6456
- uses: actions/checkout@v3
57+
with:
58+
ref: ${{ inputs.checkout-ref }}
6559
- name: Use Node.js ${{ matrix.node-version }}
6660
uses: actions/setup-node@v3
6761
with:
@@ -101,12 +95,14 @@ jobs:
10195

10296
fvtest:
10397
runs-on: ubuntu-20.04
104-
needs: [build]
98+
needs: build
10599
strategy:
106100
matrix:
107101
node-version: [18.x]
108102
steps:
109103
- uses: actions/checkout@v3
104+
with:
105+
ref: ${{ inputs.checkout-ref }}
110106
- name: Use Node.js ${{ matrix.node-version }}
111107
uses: actions/setup-node@v3
112108
with:
@@ -165,6 +161,8 @@ jobs:
165161
node-version: [18.x]
166162
steps:
167163
- uses: actions/checkout@v3
164+
with:
165+
ref: ${{ inputs.checkout-ref }}
168166
- name: Use Node.js ${{ matrix.node-version }}
169167
uses: actions/setup-node@v3
170168
with:
@@ -181,78 +179,3 @@ jobs:
181179
mkdir -p audit && cd audit && npm init -y
182180
npm install --registry http://localhost:4873 fabric-shim fabric-shim-api fabric-contract-api --save
183181
npm audit --audit-level=moderate
184-
185-
publishnpm:
186-
runs-on: ubuntu-20.04
187-
needs: [build,fvtest,src_audit]
188-
if: startsWith(github.ref, 'refs/tags/')
189-
steps:
190-
- uses: actions/setup-node@v3
191-
with:
192-
node-version: '18.x'
193-
registry-url: 'https://registry.npmjs.org'
194-
- uses: actions/download-artifact@v3
195-
with:
196-
name: node-tgzs
197-
path: build/
198-
- run: |
199-
set -xev
200-
ls -lart build/
201-
cd build
202-
find . -type f -name 'fabric-*.tgz' -exec npm publish {} \;
203-
env:
204-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
205-
206-
207-
publishdocker:
208-
runs-on: ubuntu-20.04
209-
needs: [setup,build,fvtest,src_audit]
210-
if: startsWith(github.ref, 'refs/tags/')
211-
permissions:
212-
contents: read
213-
packages: write
214-
215-
steps:
216-
- name: Set up QEMU
217-
uses: docker/setup-qemu-action@v2
218-
219-
- name: Set up Docker Buildx
220-
uses: docker/setup-buildx-action@v2
221-
with:
222-
buildkitd-flags: --debug
223-
config-inline: |
224-
[worker.oci]
225-
max-parallelism = 1
226-
227-
- name: Checkout
228-
uses: actions/checkout@v3
229-
230-
- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
231-
uses: docker/login-action@v2
232-
with:
233-
registry: ${{ env.DOCKER_REGISTRY }}
234-
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
235-
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
236-
237-
- name: Docker meta
238-
id: meta
239-
uses: docker/metadata-action@v4
240-
with:
241-
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
242-
tags: |
243-
type=semver,pattern={{version}}
244-
type=semver,pattern={{major}}.{{minor}}
245-
type=semver,pattern={{major}}.{{minor}}.{{patch}}
246-
247-
- name: Build and push ${{ matrix.COMPONENT }} Image
248-
id: push
249-
uses: docker/build-push-action@v3
250-
with:
251-
platforms: linux/amd64,linux/arm64
252-
file: docker/fabric-nodeenv/Dockerfile
253-
context: docker/fabric-nodeenv
254-
tags: ${{ steps.meta.outputs.tags }}
255-
push: ${{ github.event_name != 'pull_request' }}
256-
labels: ${{ steps.meta.outputs.labels }}
257-
build-args: |
258-
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}

0 commit comments

Comments
 (0)