Merge pull request #177 from XinFinOrg/clean-tf #137
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and publish image | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- "*" | |
workflow_dispatch: #allow manual trigger to workflow | |
jobs: | |
test_golang: | |
name: Test, build and push image to registry | |
runs-on: ubuntu-latest | |
env: | |
GOPATH: ${{ github.workspace }} | |
GOBIN: ${{ github.workspace }}/bin | |
defaults: | |
run: | |
working-directory: ${{ env.GOPATH }}/src/XDC-Subnet | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- name: A-B tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*") | |
- name: C-[a-m] tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*") | |
- name: C-[n-o] tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*") | |
- name: C-[p-z] tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*") | |
- name: D-I tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*") | |
- name: J-N tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*") | |
- name: O-R tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*") | |
- name: S tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*") | |
- name: T-Z tests | |
script: mv common/constants/constants.go.unittest common/constants.go; go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*") | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: ${{ env.GOPATH }}/src/XDC-Subnet | |
- name: Set up Go 1.21.x | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.21.x" # The Go version to download (if necessary) and use. | |
- name: Run tests | |
run: ${{ matrix.script }} | |
env: | |
GO111MODULE: auto | |
test_nodejs: | |
name: Run nodejs tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: "20.x" | |
- name: Check smart contract | |
run: | | |
cd contracts/validator/src | |
yarn | |
npx hardhat test | |
build: | |
needs: [test_golang, test_nodejs] | |
name: Build and push image to registry | |
runs-on: ubuntu-latest | |
steps: | |
- name: Docker login | |
env: | |
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} | |
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}} | |
run: | | |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | |
- name: Determine Docker Image Name | |
id: image | |
run: | | |
if [[ "${{github.ref_name}}" == "master" ]]; then | |
echo "name=xinfinorg/xdcsubnets:latest" >> $GITHUB_OUTPUT | |
else | |
echo "name=xinfinorg/xdcsubnets:${{github.ref_name}}" >> $GITHUB_OUTPUT | |
fi | |
- name: Build and push image | |
run: | | |
docker build . --file docker/Dockerfile --tag ${{ steps.image.outputs.name }} | |
docker push ${{ steps.image.outputs.name }} |