|
| 1 | +--- |
| 2 | +name: deploy-hato-bot |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - published |
| 8 | + pull_request: |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - synchronize |
| 12 | + - reopened |
| 13 | + - closed |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - master |
| 17 | + - develop |
| 18 | + |
| 19 | +jobs: |
| 20 | + deploy_docker_image: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + env: |
| 23 | + DOCKER_BUILDKIT: 1 |
| 24 | + COMPOSE_DOCKER_CLI_BUILD: 1 |
| 25 | + REPOSITORY: ${{github.repository}} |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + packages: write |
| 29 | + if: github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.action != 'closed' && github.repository == github.event.pull_request.head.repo.full_name) |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v3.1.0 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + - name: Set .env |
| 35 | + run: cp .env.example .env |
| 36 | + - name: Login to GitHub Container Registry |
| 37 | + uses: docker/login-action@v2.1.0 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + - name: Set up QEMU |
| 43 | + uses: docker/setup-qemu-action@v2.1.0 |
| 44 | + - name: Set up Docker Buildx |
| 45 | + id: buildx |
| 46 | + uses: docker/setup-buildx-action@v2.2.1 |
| 47 | + - run: echo "TAG_NAME=${HEAD_REF//\//-}" >> "$GITHUB_ENV" |
| 48 | + env: |
| 49 | + HEAD_REF: ${{github.head_ref}} |
| 50 | + if: ${{ github.event_name == 'pull_request' }} |
| 51 | + - run: echo 'TAG_NAME=${{ github.event.release.tag_name }}' >> "$GITHUB_ENV" |
| 52 | + if: ${{ github.event_name == 'release' }} |
| 53 | + - name: Build and push (build) |
| 54 | + uses: docker/bake-action@v2.3.0 |
| 55 | + env: |
| 56 | + DOCKER_CONTENT_TRUST: 1 |
| 57 | + with: |
| 58 | + push: true |
| 59 | + files: build.docker-compose.yml |
| 60 | + - name: Build and push (main) |
| 61 | + uses: docker/bake-action@v2.3.0 |
| 62 | + env: |
| 63 | + DOCKER_CONTENT_TRUST: 1 |
| 64 | + with: |
| 65 | + push: true |
| 66 | + files: docker-compose.yml |
| 67 | + - name: Build and push (dev) |
| 68 | + uses: docker/bake-action@v2.3.0 |
| 69 | + env: |
| 70 | + DOCKER_CONTENT_TRUST: 1 |
| 71 | + with: |
| 72 | + push: true |
| 73 | + files: docker-compose.yml,dev.docker-compose.yml |
| 74 | + - run: echo 'TAG_NAME=latest' >> "$GITHUB_ENV" |
| 75 | + if: ${{ github.event_name == 'release' }} |
| 76 | + - name: Build and push (build) (latest) |
| 77 | + uses: docker/bake-action@v2.3.0 |
| 78 | + if: ${{ github.event_name == 'release' }} |
| 79 | + env: |
| 80 | + DOCKER_CONTENT_TRUST: 1 |
| 81 | + with: |
| 82 | + push: true |
| 83 | + files: build.docker-compose.yml |
| 84 | + - name: Build and push (main) (latest) |
| 85 | + uses: docker/bake-action@v2.3.0 |
| 86 | + if: ${{ github.event_name == 'release' }} |
| 87 | + env: |
| 88 | + DOCKER_CONTENT_TRUST: 1 |
| 89 | + with: |
| 90 | + push: true |
| 91 | + files: docker-compose.yml |
| 92 | + - name: Build and push (dev) (latest) |
| 93 | + uses: docker/bake-action@v2.3.0 |
| 94 | + if: ${{ github.event_name == 'release' }} |
| 95 | + env: |
| 96 | + DOCKER_CONTENT_TRUST: 1 |
| 97 | + with: |
| 98 | + push: true |
| 99 | + files: docker-compose.yml,dev.docker-compose.yml |
| 100 | + - name: Start docker |
| 101 | + env: |
| 102 | + DOCKER_CONTENT_TRUST: 1 |
| 103 | + run: bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/deploy_docker_image/test.sh" |
| 104 | + |
| 105 | + # .python-version をDockerイメージと同期させる |
| 106 | + update-version-python-version: |
| 107 | + runs-on: ubuntu-latest |
| 108 | + permissions: |
| 109 | + contents: write |
| 110 | + pull-requests: write |
| 111 | + env: |
| 112 | + DOCKER_CONTENT_TRUST: 1 |
| 113 | + REPOSITORY: ${{github.repository}} |
| 114 | + needs: deploy_docker_image |
| 115 | + if: always() && (needs.deploy_docker_image.result == 'success' || (github.event_name == 'pull_request' && github.event.action == 'closed')) |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v3.1.0 |
| 118 | + with: |
| 119 | + fetch-depth: 0 |
| 120 | + ref: ${{ github.event.pull_request.head.sha }} |
| 121 | + - name: Get Python version |
| 122 | + id: get_python_version |
| 123 | + run: bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/update_version_python_version/get_python_version.sh" |
| 124 | + env: |
| 125 | + HEAD_REF: ${{github.head_ref}} |
| 126 | + - uses: dev-hato/actions-diff-pr-management@v1.1.1 |
| 127 | + with: |
| 128 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 129 | + branch-name-prefix: fix-version-python-version |
| 130 | + pr-title-prefix: .python-versionを直してあげたよ! |
| 131 | + |
| 132 | + update-dockle: |
| 133 | + runs-on: ubuntu-latest |
| 134 | + steps: |
| 135 | + - uses: actions/checkout@v3.1.0 |
| 136 | + with: |
| 137 | + fetch-depth: 0 |
| 138 | + ref: ${{ github.event.pull_request.head.sha }} |
| 139 | + - uses: dev-hato/actions-update-dockle@v0.0.33 |
| 140 | + with: |
| 141 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 142 | + repo-name: dev-hato/hato-bot |
| 143 | + |
| 144 | + dockle: |
| 145 | + runs-on: ubuntu-latest |
| 146 | + needs: |
| 147 | + - update-dockle |
| 148 | + - deploy_docker_image |
| 149 | + env: |
| 150 | + DOCKER_CONTENT_TRUST: 1 |
| 151 | + REPOSITORY: ${{github.repository}} |
| 152 | + steps: |
| 153 | + - uses: actions/checkout@v3.1.0 |
| 154 | + - run: bash "${GITHUB_WORKSPACE}/scripts/deploy_hato_bot/dockle/run_dockle.sh" |
| 155 | + env: |
| 156 | + HEAD_REF: ${{github.head_ref}} |
| 157 | + |
| 158 | + deploy-complete: |
| 159 | + runs-on: ubuntu-latest |
| 160 | + if: always() |
| 161 | + needs: |
| 162 | + - update-version-python-version |
| 163 | + - update-dockle |
| 164 | + - dockle |
| 165 | + steps: |
| 166 | + - if: needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success'))) |
| 167 | + run: exit 0 |
| 168 | + - if: ${{ !(needs.update-dockle.result == 'success' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name) || (needs.update-version-python-version.result == 'success' && (github.event.action == 'closed' || needs.dockle.result == 'success')))) }} |
| 169 | + run: exit 1 |
| 170 | + |
| 171 | +concurrency: |
| 172 | + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} |
| 173 | + cancel-in-progress: true |
0 commit comments