|
| 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-command |
| 4 | +on: |
| 5 | + repository_dispatch: |
| 6 | + types: [test-command] |
| 7 | + |
| 8 | +jobs: |
| 9 | + |
| 10 | + build: |
| 11 | + env: |
| 12 | + AUTHORIZED: ${{ github.actor != github.event.client_payload.pull_request.base.repo.owner.login }} |
| 13 | + SOURCE_BRANCH: master |
| 14 | + DOCKER_REPO: embercsi/ci_images |
| 15 | + IMAGE_TAG: ${{ format('{0}-{1}', github.event.client_payload.pull_request.number, github.event.client_payload.pull_request.head.sha) }} |
| 16 | + DETAILS_URL: ${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }} |
| 17 | + JOB_NAME: internal/build-pr-images |
| 18 | + TAGS_MISSING: false |
| 19 | + |
| 20 | + # In the future we may want to return embercsi/ember-csi:{master,latest} |
| 21 | + outputs: |
| 22 | + image_base_name: ${{ format('{0}:{1}-', env.DOCKER_REPO, env.IMAGE_TAG) }} |
| 23 | + |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + # Checkout the pull request branch from the repository |
| 27 | + - uses: actions/checkout@v2 |
| 28 | + if: env.AUTHORIZED == 'true' |
| 29 | + with: |
| 30 | + token: ${{ secrets.TOKEN }} |
| 31 | + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} |
| 32 | + ref: ${{ github.event.client_payload.pull_request.head.ref }} |
| 33 | + |
| 34 | + - name: Notify in_progress |
| 35 | + run: | |
| 36 | + 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 }}" |
| 37 | +
|
| 38 | + - name: Check if images exist |
| 39 | + if: env.AUTHORIZED == 'true' |
| 40 | + run: | |
| 41 | + for i in 7 8; do |
| 42 | + tag_info=`curl -fL --silent ${{ format('https://hub.docker.com/v2/repositories/{0}/tags/{1}', env.DOCKER_REPO, env.IMAGE_TAG) }}-$i` |
| 43 | + if [[ ! $tag_info == *'"name"'* ]]; then |
| 44 | + echo "::set-env name=TAGS_MISSING::true" |
| 45 | + break |
| 46 | + fi |
| 47 | + done |
| 48 | +
|
| 49 | + - name: Build images |
| 50 | + if: env.AUTHORIZED == 'true' && env.TAGS_MISSING == 'true' |
| 51 | + run: | |
| 52 | + echo 'Start' |
| 53 | + echo "::add-mask::${{ secrets.DOCKER_PASSWORD }}" |
| 54 | + EMBER_VERSION=$IMAGE_TAG hooks/build |
| 55 | + echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin |
| 56 | + docker tag $DOCKER_REPO:master7 $DOCKER_REPO:${IMAGE_TAG}-7 |
| 57 | + docker tag $DOCKER_REPO:master8 $DOCKER_REPO:${IMAGE_TAG}-8 |
| 58 | + docker push $DOCKER_REPO:${IMAGE_TAG}-7 |
| 59 | + docker push $DOCKER_REPO:${IMAGE_TAG}-8 |
| 60 | + echo 'Done' |
| 61 | +
|
| 62 | + - name: Get result status |
| 63 | + if: always() |
| 64 | + run: | |
| 65 | + status=`echo "${{ job.status }}" | tr '[:upper:]' '[:lower:]'` |
| 66 | + if [[ "$status" == "cancelled" ]]; then |
| 67 | + echo "::set-env name=JOB_RESULT::error" |
| 68 | + else |
| 69 | + echo "::set-env name=JOB_RESULT::$status" |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Notify result status |
| 73 | + if: always() |
| 74 | + run: | |
| 75 | + 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 }}" |
| 76 | +
|
| 77 | + testing: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: build |
| 80 | + strategy: |
| 81 | + matrix: |
| 82 | + centos: [7, 8] |
| 83 | + steps: |
| 84 | + - name: Testing |
| 85 | + run: | |
| 86 | + pwd |
| 87 | + echo Running with backend ${{ matrix.backend }} on a Centos ${{ matrix.centos }} VM |
| 88 | + echo Job is ${{ job }} |
0 commit comments