[CI] Add some basic tests #15
This file contains hidden or 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 images | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| workflow_dispatch: | |
| jobs: | |
| build-linux: | |
| uses: ./.github/workflows/define-build-linux-image.yaml | |
| secrets: inherit | |
| test-linux: | |
| needs: [build-linux] | |
| runs-on: [self-hosted, linux] | |
| steps: | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - name: Download cached docker image | |
| run: | | |
| curl -X GET http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar -o /tmp/image_ubuntu.tar | |
| - name: Load image | |
| run: | | |
| docker load --input /tmp/image_ubuntu.tar | |
| - name: Run container with tests | |
| if: failure() | |
| run: | | |
| docker run --name gha-runner --runtime sysbox-runc -e TEST_ONLY_RUN=yes -e REPO=Ableytner/docker-github-actions-runner -e TOKEN=XXXX ${{ env.IMAGE_NAME }}:latest-ubuntu | |
| if [[ $? -ne 0 ]]; then | |
| echo "tests failed!" | |
| exit 1 | |
| fi | |
| - name: Print out server container logs | |
| if: failure() | |
| run: | | |
| docker logs gha-runner | |
| - name: Stop and delete server container | |
| if: always() | |
| run: | | |
| docker rm -f gha-runner | |
| push: | |
| needs: [test-linux] | |
| runs-on: [self-hosted, linux] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - name: Download cached docker image | |
| run: | | |
| curl -X GET http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar -o /tmp/image_ubuntu.tar | |
| - name: Load image | |
| run: | | |
| docker load --input /tmp/image_ubuntu.tar | |
| - name: Push | |
| run: | | |
| docker tag ${{ env.IMAGE_NAME }}:latest-ubuntu ghcr.io/${{ env.IMAGE_NAME }}:dev | |
| docker push ghcr.io/${{ env.IMAGE_NAME }}:dev | |
| - name: Remove local image | |
| if: always() | |
| run: | | |
| docker image rm ${{ env.IMAGE_NAME }}:latest-ubuntu | |
| - name: Remove cached docker image | |
| if: always() | |
| run: | | |
| curl -X DELETE http://192.168.0.11:25000/attachments/gha-runner/1/image_ubuntu.tar |