|
| 1 | +name: CI Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] # Trigger when the PR is closed (merged or just closed) |
| 6 | + branches: |
| 7 | + - master # Trigger only when code is pushed to the master branch |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + # Run the jobs only if the PR is merged and the label 'CI:Build' is present |
| 12 | + if: contains(github.event.pull_request.labels.*.name, 'CI:Build') && github.event.pull_request.merged == true |
| 13 | + runs-on: ubuntu:latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout Code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Get Version and Build number |
| 20 | + run: | |
| 21 | + VERSION="latest" # Simple static version; could be changed if needed |
| 22 | + BUILDNUM=${GITHUB_RUN_NUMBER} # Use the GitHub run number as the build number |
| 23 | +
|
| 24 | + # Set environment variables for later steps |
| 25 | + echo "VERSION=${VERSION}" >> $GITHUB_ENV |
| 26 | + echo "BUILDNUM=${BUILDNUM}" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@v3 |
| 30 | + |
| 31 | + - name: Set up Docker Login |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 35 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 36 | + |
| 37 | + - name: Build Docker image |
| 38 | + run: | |
| 39 | + docker build -t ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} . |
| 40 | +
|
| 41 | + - name: Tag Docker image with 'latest' |
| 42 | + run: | |
| 43 | + docker tag ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} ${{ secrets.DOCKER_USERNAME }}/go-ethereum:latest |
| 44 | + |
| 45 | + - name: Push Docker image to Docker Hub |
| 46 | + run: | |
| 47 | + docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} |
| 48 | + docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum:latest |
| 49 | +
|
| 50 | + run-devnet: |
| 51 | + needs: build # Ensure this runs only after the build-and-push job |
| 52 | + runs-on: ubuntu-latest |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Checkout Code |
| 56 | + uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Set up Docker Compose |
| 59 | + run: | |
| 60 | + sudo apt-get update |
| 61 | + sudo apt-get install -y docker-compose |
| 62 | +
|
| 63 | + - name: Log in to Docker Hub |
| 64 | + uses: docker/login-action@v2 |
| 65 | + with: |
| 66 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 67 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 68 | + |
| 69 | + - name: Run Devnet with Docker Compose |
| 70 | + run: | |
| 71 | + export DOCKER_HUB_USER=${{ secrets.DOCKER_USERNAME }} |
| 72 | + docker-compose up -d |
| 73 | +
|
| 74 | + - name: Verify Devnet |
| 75 | + run: | |
| 76 | + sleep 10 # Allow time for the devnet to start |
| 77 | + curl -X POST -H "Content-Type: application/json" \ |
| 78 | + --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \ |
| 79 | + http://localhost:8545 |
| 80 | +
|
| 81 | + - name: Stop Devnet container |
| 82 | + run: | |
| 83 | + docker-compose down # Stops the containers and removes the network |
0 commit comments