|
| 1 | +name: Build and deploy devnet |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + |
| 7 | +jobs: |
| 8 | + build_and_deploy: |
| 9 | + if: startsWith(github.head_ref, 'feature') || startsWith(github.head_ref, 'fix') |
| 10 | + name: Deploy on PR |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Check out code |
| 14 | + uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: check out trigger branch |
| 17 | + run: | |
| 18 | + git fetch origin ${{ github.head_ref }} |
| 19 | + git checkout ${{ github.head_ref }} |
| 20 | +
|
| 21 | + # - name: check envs |
| 22 | + # run: | |
| 23 | + # echo ${{ github.head_ref }} |
| 24 | + # echo ${{ github.repository }} |
| 25 | + # echo ${{ github.ref_name }} |
| 26 | + # echo ${{ github.sha }} |
| 27 | + |
| 28 | + - name: Record branch env |
| 29 | + id: branch |
| 30 | + run: | |
| 31 | + echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT |
| 32 | + echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT |
| 33 | + echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 34 | + # echo $repo |
| 35 | + # echo $branch |
| 36 | + # echo $commit |
| 37 | +
|
| 38 | + - name: Docker login |
| 39 | + env: |
| 40 | + DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} |
| 41 | + DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}} |
| 42 | + run: | |
| 43 | + echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin |
| 44 | +
|
| 45 | + - name: Determine Docker Image Name |
| 46 | + id: image |
| 47 | + run: | |
| 48 | + echo "name=xinfinorg/xdcsubnets:${{ steps.branch.outputs.branch }}" >> $GITHUB_OUTPUT |
| 49 | + |
| 50 | +
|
| 51 | + - name: Build and push image |
| 52 | + run: | |
| 53 | + docker build . --file docker/Dockerfile --tag ${{ steps.image.outputs.name }} |
| 54 | + docker push ${{ steps.image.outputs.name }} |
| 55 | +
|
| 56 | + - name: trigger deploy workflow |
| 57 | + id: trigger_deploy |
| 58 | + run: | |
| 59 | + echo "RESPONSE_CODE=$( \ |
| 60 | + curl -L \ |
| 61 | + -o response.txt \ |
| 62 | + -w %{response_code} \ |
| 63 | + -s \ |
| 64 | + -X POST \ |
| 65 | + -H "Accept: application/vnd.github+json" \ |
| 66 | + -H "Authorization: Bearer ${{ secrets.CICD_PAT }}" \ |
| 67 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 68 | + https://api.github.com/repos/hash-laboratories-au/subnet-deployment/actions/workflows/subnet-deploy.yaml/dispatches \ |
| 69 | + -d '{"ref":"master", "inputs":{"caller_repo": "${{ steps.branch.outputs.repo }}", "caller_ref": "${{ steps.branch.outputs.branch }}", "caller_sha": "${{ steps.branch.outputs.commit }}"}}' \ |
| 70 | + )" >> $GITHUB_ENV |
| 71 | +
|
| 72 | + - name: Check response fail or success |
| 73 | + run: | |
| 74 | + cat response.txt |
| 75 | + echo "RESPONSE_CODE=${{ env.RESPONSE_CODE }}" |
| 76 | + if [ ${{ env.RESPONSE_CODE }} != 204 ] |
| 77 | + then |
| 78 | + exit 1 |
| 79 | + fi |
0 commit comments