You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.6 KiB

  1. name: catalog-api
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - dev
  7. paths:
  8. - src/BuildingBlocks/**
  9. - src/Services/Catalog/**
  10. - .github/workflows/catalog-api.yml
  11. pull_request:
  12. branches:
  13. - dev
  14. paths:
  15. - src/BuildingBlocks/**
  16. - src/Services/Catalog/**
  17. - .github/workflows/catalog-api.yml
  18. env:
  19. SERVICE: catalog-api
  20. IMAGE: catalog.api
  21. DOTNET_VERSION: 5.0.x
  22. jobs:
  23. BuildContainersForPR_Linux:
  24. runs-on: ubuntu-latest
  25. if: ${{ github.event_name == 'pull_request' }}
  26. steps:
  27. - name: 'Checkout Github Action'
  28. uses: actions/checkout@master
  29. - name: Setup dotnet
  30. uses: actions/setup-dotnet@v1
  31. with:
  32. dotnet-version: ${{ env.DOTNET_VERSION }}
  33. - name: Build and run unit tests
  34. run: |
  35. cd src
  36. dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
  37. cd Services/Catalog/Catalog.API
  38. dotnet build --no-restore
  39. cd -
  40. cd Services/Catalog/Catalog.UnitTests
  41. dotnet build --no-restore
  42. dotnet test --no-build -v=normal
  43. - name: Compose build ${{ env.SERVICE }}
  44. run: sudo -E docker-compose build ${{ env.SERVICE }}
  45. working-directory: ./src
  46. shell: bash
  47. env:
  48. TAG: ${{ env.BRANCH }}
  49. REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
  50. BuildLinux:
  51. runs-on: ubuntu-latest
  52. if: ${{ github.event_name != 'pull_request' }}
  53. steps:
  54. - name: 'Checkout Github Action'
  55. uses: actions/checkout@master
  56. - name: Setup dotnet
  57. uses: actions/setup-dotnet@v1
  58. with:
  59. dotnet-version: ${{ env.DOTNET_VERSION }}
  60. - name: Build and run unit tests
  61. run: |
  62. cd src
  63. dotnet restore "eShopOnContainers-ServicesAndWebApps.sln"
  64. cd Services/Catalog/Catalog.API
  65. dotnet build --no-restore
  66. cd -
  67. cd Services/Catalog/Catalog.UnitTests
  68. dotnet build --no-restore
  69. dotnet test --no-build -v=normal
  70. - name: Enable experimental features for the Docker daemon and CLI
  71. run: |
  72. echo $'{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json
  73. mkdir -p ~/.docker
  74. echo $'{\n "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
  75. sudo service docker restart
  76. docker version -f '{{.Client.Experimental}}'
  77. docker version -f '{{.Server.Experimental}}'
  78. - name: Login to Container Registry
  79. uses: docker/login-action@v1
  80. with:
  81. registry: ${{ secrets.REGISTRY_HOST }}
  82. username: ${{ secrets.USERNAME }}
  83. password: ${{ secrets.PASSWORD }}
  84. - name: Set branch name as env variable
  85. run: |
  86. currentbranch=$(echo ${GITHUB_REF##*/})
  87. echo "running on $currentbranch"
  88. echo "BRANCH=$currentbranch" >> $GITHUB_ENV
  89. shell: bash
  90. - name: Compose build ${{ env.SERVICE }}
  91. run: sudo -E docker-compose build ${{ env.SERVICE }}
  92. working-directory: ./src
  93. shell: bash
  94. env:
  95. TAG: ${{ env.BRANCH }}
  96. REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
  97. - name: Compose push ${{ env.SERVICE }}
  98. run: sudo -E docker-compose push ${{ env.SERVICE }}
  99. working-directory: ./src
  100. shell: bash
  101. env:
  102. TAG: ${{ env.BRANCH }}
  103. REGISTRY: ${{ secrets.REGISTRY_ENDPOINT }}
  104. - name: Create multiarch manifest
  105. run: |
  106. docker --config ~/.docker manifest create ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }} ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:linux-${{ env.BRANCH }}
  107. docker --config ~/.docker manifest push ${{ secrets.REGISTRY_ENDPOINT }}/${{ env.IMAGE }}:${{ env.BRANCH }}
  108. shell: bash