|
4 | 4 | workflow_dispatch:
|
5 | 5 | inputs:
|
6 | 6 | tag:
|
7 |
| - description: 'Tag for the Docker image' |
| 7 | + description: 'tag for the Docker image' |
8 | 8 | required: true
|
9 | 9 | default: 'latest'
|
10 | 10 | push:
|
11 | 11 | branches:
|
12 | 12 | - 'main'
|
13 |
| - paths: |
14 |
| - - '**/Dockerfile' |
15 |
| - |
16 | 13 | jobs:
|
| 14 | + define-matrix: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + tag: ${{ steps.set_tag.outputs.tag }} |
| 18 | + tag_cn: ${{ steps.set_tag.outputs.tag_cn }} |
| 19 | + build_targets: ${{ steps.get_build_matrix.outputs.build_targets }} |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + - name: Set up tag |
| 26 | + id: set_tag |
| 27 | + run: | |
| 28 | + if [ -n "${{ inputs.tag }}" ]; then |
| 29 | + tag=${{ inputs.tag }} |
| 30 | + else |
| 31 | + tag=${{ github.sha }}::6 |
| 32 | + fi |
| 33 | + tag_cn=$tag-cn |
| 34 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 35 | + echo "tag_cn=$tag_cn" >> $GITHUB_OUTPUT |
| 36 | + - name: Get build matrix |
| 37 | + id: get_build_matrix |
| 38 | + run: | |
| 39 | + if [ -n "${{ inputs.tag }}" ]; then |
| 40 | + build_targets=$(bash script/get_all_dockerfile.sh) |
| 41 | + else |
| 42 | + build_targets=$(bash script/get_changed_dockerfile.sh ${{ github.event.before }} ${{ github.sha }}) |
| 43 | + fi |
| 44 | + echo "build_targets=$build_targets" >> $GITHUB_OUTPUT |
17 | 45 | build:
|
18 | 46 | runs-on: ubuntu-latest
|
19 |
| - |
| 47 | + needs: define-matrix |
| 48 | + strategy: |
| 49 | + matrix: |
| 50 | + build_target: ${{ fromJson(needs.define-matrix.outputs.build_targets) }} |
20 | 51 | steps:
|
21 | 52 | - name: Checkout code
|
22 | 53 | uses: actions/checkout@v4
|
23 | 54 | with:
|
24 | 55 | fetch-depth: 0
|
25 |
| - |
26 | 56 | - name: Set up QEMU
|
27 | 57 | uses: docker/setup-qemu-action@v3
|
28 |
| - |
29 |
| - - name: Set up tag |
30 |
| - id: set_tag |
31 |
| - run: | |
32 |
| - if [ -n "$INPUT_TAG" ]; then |
33 |
| - TAG=$INPUT_TAG |
34 |
| - else |
35 |
| - TAG=${COMMIT_ID::6} |
36 |
| - fi |
37 |
| - CN_TAG=$INPUT_TAG-cn |
38 |
| -
|
39 |
| - echo "TAG=$TAG" >> $GITHUB_ENV |
40 |
| - echo "CN_TAG=$CN_TAG" >> $GITHUB_ENV |
41 |
| - echo "TAG=$TAG" >> $GITHUB_OUTPUT |
42 |
| - echo "CN_TAG=$CN_TAG" >> $GITHUB_OUTPUT |
43 |
| -
|
44 |
| - - name: Get changed files |
45 |
| - id: getfile |
46 |
| - run: | |
47 |
| - bash script/get_changed_files.sh ${{ github.event.before }} ${{ github.sha }} |
48 |
| - shell: bash |
49 |
| - |
50 |
| - - name: Echo output |
51 |
| - run: | |
52 |
| - echo "Changed files: ${{ env.DIFF_OUTPUT }}" |
53 |
| - echo "Parent directories: ${{ env.PARENT_DIRS }}" |
54 |
| -
|
55 | 58 | - name: Set up Docker Buildx
|
56 | 59 | uses: docker/setup-buildx-action@v3
|
57 |
| - |
58 | 60 | - name: Login to ghcr.io
|
59 | 61 | uses: docker/login-action@v3
|
60 | 62 | with:
|
61 | 63 | registry: ghcr.io
|
62 | 64 | username: ${{ github.repository_owner }}
|
63 | 65 | password: ${{ secrets.GH_PAT }}
|
64 |
| - |
65 | 66 | - name: Build and push image
|
66 | 67 | run: |
|
67 |
| - bash script/build_and_push_images.sh ${{ steps.set_tag.outputs.TAG }} ${{ steps.set_tag.outputs.CN_TAG }} |
68 |
| - env: |
69 |
| - USERNAME: ${{ github.repository_owner }} |
70 |
| - COMMIT_ID: ${{ github.sha }} |
71 |
| - shell: bash |
72 |
| - |
73 |
| - - uses: actions/checkout@v3 |
74 |
| - - name: generate runtime yaml |
75 |
| - run: | |
76 |
| - bash script/generate_runtime_yaml.sh ${{ steps.set_tag.outputs.TAG }} ${{ steps.set_tag.outputs.CN_TAG }} |
77 |
| - bash script/generate_json.sh ${{ steps.set_tag.outputs.TAG }} ${{ steps.set_tag.outputs.CN_TAG }} |
78 |
| - env: |
79 |
| - DOCKER_USERNAME: ${{ github.repository_owner }} |
80 |
| - COMMIT_ID: ${{ github.sha }} |
81 |
| - shell: bash |
82 |
| - |
83 |
| - - uses: stefanzweifel/git-auto-commit-action@v5 |
84 |
| - with: |
85 |
| - commit_message: auto generate runtime yaml |
| 68 | + echo "build_target=$build_target" |
| 69 | + echo "tag=${{ needs.define-matrix.outputs.tag }}" |
| 70 | + echo "tag_cn=${{ needs.define-matrix.outputs.tag_cn }}" |
| 71 | + image_name=$(bash script/get_image_name.sh ${{ github.repository_owner }} $build_target ${{ needs.define-matrix.outputs.tag }}) |
| 72 | + image_name_cn=$(bash script/get_image_name.sh ${{ github.repository_owner }} $build_target ${{ needs.define-matrix.outputs.tag_cn }}) |
| 73 | + echo "image_name=$image_name" >> $GITHUB_OUTPUT |
| 74 | + echo "image_name_cn=$image_name_cn" >> $GITHUB_OUTPUT |
| 75 | + is_cn=0 bash script/build_and_push_images.sh $build_target $image_name $is_cn |
| 76 | + is_cn=1 bash script/build_and_push_images.sh $build_target $image_name_cn $is_cn |
| 77 | + # TODO: generate runtime yaml and json |
0 commit comments