|
| 1 | +# TODO: Don't build if the PR is not based on master's HEAD |
| 2 | +# TODO: Only build the container if specific directories/files have changed, unless forced: https://coderwall.com/p/lz0uva/find-all-files-modified-between-commits-in-git |
| 3 | +name: test-pr-${{ github.event.client_payload.pull_request.number }}-${{ github.event.client_payload.pull_request.head.sha) }} |
| 4 | +on: |
| 5 | + repository_dispatch: |
| 6 | + types: [test-command] |
| 7 | +env: |
| 8 | + AUTHORIZED: ${{ github.actor != github.event.client_payload.pull_request.base.repo.owner.login }} |
| 9 | + DETAILS_URL: ${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }} |
| 10 | + DOCKER_REPO: embercsi/ci_images |
| 11 | + IMAGE_TAG: ${{ format('{0}-{1}', github.event.client_payload.pull_request.number, github.event.client_payload.pull_request.head.sha) }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + build: |
| 16 | + name: internal/build-pr-images |
| 17 | + env: |
| 18 | + JOB_NAME: internal/build-pr-images |
| 19 | + TAGS_MISSING: false |
| 20 | + |
| 21 | + # In the future we may want to return embercsi/ember-csi:{master,latest} |
| 22 | + outputs: |
| 23 | + image_base_name: ${{ format('{0}:{1}-', env.DOCKER_REPO, env.IMAGE_TAG) }} |
| 24 | + |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + # Checkout the pull request branch from the repository |
| 28 | + - uses: actions/checkout@v2 |
| 29 | + if: env.AUTHORIZED == 'true' |
| 30 | + with: |
| 31 | + token: ${{ secrets.TOKEN }} |
| 32 | + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} |
| 33 | + ref: ${{ github.event.client_payload.pull_request.head.ref }} |
| 34 | + |
| 35 | + - name: Write comment |
| 36 | + uses: peter-evans/create-or-update-comment@v1 |
| 37 | + with: |
| 38 | + token: ${{ secrets.EMBERIO_ACCESS_TOKEN }} |
| 39 | + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} |
| 40 | + issue-number: ${{ github.event.client_payload.pull_request.number }} |
| 41 | + # comment-id: ${{ github.event.client_payload.github.payload.comment.id }} |
| 42 | + body: | |
| 43 | + [Test workflow has started][1] |
| 44 | +
|
| 45 | + [1]: ${{ env.DETAILS_URL }} |
| 46 | +
|
| 47 | + - name: Notify in_progress |
| 48 | + if: env.AUTHORIZED == 'true' |
| 49 | + run: ./tools/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} pending ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }} |
| 50 | + #run: | |
| 51 | + # curl -X POST -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" -d '{"context": "${{ env.JOB_NAME }}","state": "pending","target_url": "${{ env.DETAILS_URL }}"}' "https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }}" |
| 52 | + env: |
| 53 | + TOKEN: ${{ secrets.TOKEN }} |
| 54 | + |
| 55 | + - name: Check if images exist |
| 56 | + if: env.AUTHORIZED == 'true' |
| 57 | + run: | |
| 58 | + for i in 7 8; do |
| 59 | + if ! curl -L --silent ${{ format('https://hub.docker.com/v2/repositories/{0}/tags/{1}', env.DOCKER_REPO, env.IMAGE_TAG) }}-$i | grep '"name"'; then |
| 60 | + echo "::set-env name=TAGS_MISSING::true" |
| 61 | + break |
| 62 | + fi |
| 63 | + done |
| 64 | +
|
| 65 | + - name: Build images |
| 66 | + if: env.AUTHORIZED == 'true' && env.TAGS_MISSING == 'true' |
| 67 | + run: | |
| 68 | + echo 'Start' |
| 69 | + echo "::add-mask::${{ secrets.DOCKER_PASSWORD }}" |
| 70 | + EMBER_VERSION=$IMAGE_TAG SOURCE_BRANCH=master hooks/build |
| 71 | + echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin |
| 72 | + docker tag $DOCKER_REPO:master7 $DOCKER_REPO:${IMAGE_TAG}-7 |
| 73 | + docker tag $DOCKER_REPO:master8 $DOCKER_REPO:${IMAGE_TAG}-8 |
| 74 | + docker push $DOCKER_REPO:${IMAGE_TAG}-7 |
| 75 | + docker push $DOCKER_REPO:${IMAGE_TAG}-8 |
| 76 | + echo 'Done' |
| 77 | +
|
| 78 | + # - name: Get result status |
| 79 | + # if: always() && env.AUTHORIZED == 'true' |
| 80 | + # run: | |
| 81 | + # status=`echo "${{ job.status }}" | tr '[:upper:]' '[:lower:]'` |
| 82 | + # if [[ "$status" == "cancelled" ]]; then |
| 83 | + # echo "::set-env name=JOB_RESULT::error" |
| 84 | + # else |
| 85 | + # echo "::set-env name=JOB_RESULT::$status" |
| 86 | + # fi |
| 87 | + |
| 88 | + - name: Notify result status |
| 89 | + if: always() && env.AUTHORIZED == 'true' |
| 90 | + run: ./tools/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} ${{ job.status }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }} |
| 91 | + # run: | |
| 92 | + # curl -X POST -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" -d '{"context": "${{ env.JOB_NAME }}","state": "${{ env.JOB_RESULT }}","target_url": "${{ env.DETAILS_URL }}"}' "https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }}" |
| 93 | + env: |
| 94 | + TOKEN: ${{ secrets.TOKEN }} |
| 95 | + |
| 96 | + |
| 97 | + functional: |
| 98 | + needs: build |
| 99 | + strategy: |
| 100 | + fail-fast: false |
| 101 | + matrix: |
| 102 | + centos: [7, 8] |
| 103 | + backend: [lvm, ceph] |
| 104 | + csi: [v1.1] |
| 105 | + include: |
| 106 | + - centos: 7 |
| 107 | + backend: lvm |
| 108 | + csi: v1.0 |
| 109 | + - centos: 7 |
| 110 | + backend: lvm |
| 111 | + csi: v0.3 |
| 112 | + - centos: 7 |
| 113 | + backend: lvm |
| 114 | + csi: v0.2 |
| 115 | + name: "3rdparty/${{ matrix.backend }}-functional-centos${{ matrix.centos }}-csi_${{ matrix.csi }}" |
| 116 | + runs-on: ${{ matrix.backend }} |
| 117 | + # Fails: |
| 118 | + # runs-on: [self-hosted, ${{ matrix.backend }}] |
| 119 | + # runs-on: "[self-hosted, ${{ matrix.backend }}]" |
| 120 | + # runs-on: ${{ format('[ self-hosted, {0} ]', matrix.backend) }} |
| 121 | + # These work: |
| 122 | + #runs-on: [self-hosted, lvm] |
| 123 | + # runs-on: self-hosted |
| 124 | + env: |
| 125 | + JOB_NAME: "3rdparty/${{ matrix.backend }}-functional-centos${{ matrix.centos }}-csi_${{ matrix.csi }}" |
| 126 | + BACKEND_NAME: ${{ matrix.backend }} |
| 127 | + steps: |
| 128 | + # Checkout the pull request branch from the repository |
| 129 | + - uses: actions/checkout@v2 |
| 130 | + if: env.AUTHORIZED == 'true' |
| 131 | + with: |
| 132 | + repository: embercsi/3rd-party-ci |
| 133 | + ref: gh-actions |
| 134 | + |
| 135 | + - name: Notify in_progress |
| 136 | + # run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} pending ${{ env.DETAILS_URL }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }} |
| 137 | + run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} pending ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }} |
| 138 | + env: |
| 139 | + TOKEN: ${{ secrets.TOKEN }} |
| 140 | + |
| 141 | + - name: Testing |
| 142 | + run: | |
| 143 | + pwd |
| 144 | + export HOST_IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) |
| 145 | + echo Running with backend ${{ matrix.backend }} on a Centos ${{ matrix.centos }} VM |
| 146 | + ./ci-scripts/vm-run-functional.sh |
| 147 | + env: |
| 148 | + EMBER_IMAGE: ${{needs.build.outputs.image_base_name}} |
| 149 | + CENTOS_VERSION: ${{matrix.centos}} |
| 150 | + JOB_ID: ${{github.run_id}} |
| 151 | + CSI_SPEC_VERSION: ${{matrix.csi}} |
| 152 | + # BACKEND_NAME: ${{matrix.backend}} |
| 153 | + |
| 154 | + - name: Upload artifacts |
| 155 | + if: always() |
| 156 | + uses: actions/upload-artifact@v2-preview |
| 157 | + with: |
| 158 | + name: "${{ matrix.backend }}-functional-centos${{ matrix.centos }}-artifacts" |
| 159 | + path: 'artifacts/*' |
| 160 | + |
| 161 | + - name: Notify result status |
| 162 | + if: always() |
| 163 | + # run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ job.status }} ${{ env.DETAILS_URL }} ${{ github.repository }} |
| 164 | + run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} ${{ job.status }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }} |
| 165 | + env: |
| 166 | + TOKEN: ${{ secrets.TOKEN }} |
0 commit comments