From c5b8d3f89a47f38a067002d45720123c04f065a0 Mon Sep 17 00:00:00 2001 From: Yelin Jeong Date: Mon, 13 May 2024 12:43:25 +0900 Subject: [PATCH] [action] Add check-rebuild reusable workflows This patch adds check-rebuild reusable workflows and replace each step in workflow. Signed-off-by: Yelin Jeong --- .github/actions/check-rebuild/action.yml | 20 ++++++++++++++++++++ .../check-rebuild}/check_if_rebuild_requires.sh | 0 .github/workflows/android.yml | 16 ++++++---------- .github/workflows/gbs_build.yml | 13 +++---------- .github/workflows/macos.yaml | 11 +++-------- .github/workflows/pdebuild.yml | 11 +++-------- .github/workflows/risc-v.yml | 11 +++-------- .github/workflows/ubuntu_clean_llvm_build.yml | 14 +++++--------- .github/workflows/ubuntu_clean_meson_build.yml | 14 +++++--------- .github/workflows/yocto.yml | 11 +++-------- 10 files changed, 51 insertions(+), 70 deletions(-) create mode 100644 .github/actions/check-rebuild/action.yml rename .github/{workflows => actions/check-rebuild}/check_if_rebuild_requires.sh (100%) diff --git a/.github/actions/check-rebuild/action.yml b/.github/actions/check-rebuild/action.yml new file mode 100644 index 0000000..cdf20e9 --- /dev/null +++ b/.github/actions/check-rebuild/action.yml @@ -0,0 +1,20 @@ +name: Check if rebuild required +description: + +inputs: + mode: + description: build mode to be checked + required: false + default: build + +runs: + using: composite + steps: + - run: | + tmpfile=$(mktemp) + git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} + echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" + rebuild=`bash .github/actions/check-rebuild/check_if_rebuild_requires.sh ${tmpfile} ${{ inputs.mode }} | grep "REBUILD=YES" | wc -l` + echo "Rebuild required: ${rebuild}" + echo "rebuild=${rebuild}" >> "$GITHUB_ENV" + shell: sh diff --git a/.github/workflows/check_if_rebuild_requires.sh b/.github/actions/check-rebuild/check_if_rebuild_requires.sh similarity index 100% rename from .github/workflows/check_if_rebuild_requires.sh rename to .github/actions/check-rebuild/check_if_rebuild_requires.sh diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 973fe61..b62d949 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -12,19 +12,15 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: -${{ github.event.pull_request.commits }} - - uses: nttld/setup-ndk@v1 + - name: Check if rebuild required + uses: ./.github/actions/check-rebuild + with: + mode: android + - if: env.rebuild == '1' + uses: nttld/setup-ndk@v1 with: ndk-version: r12b link-to-sdk: true - - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} android | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" ## @todo Make cache works (daily update cache on main branch / restore the cache on each PR (w/o saving)) - name: Prepare Build if: env.rebuild == '1' diff --git a/.github/workflows/gbs_build.yml b/.github/workflows/gbs_build.yml index acf614b..d196bc0 100644 --- a/.github/workflows/gbs_build.yml +++ b/.github/workflows/gbs_build.yml @@ -29,17 +29,10 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: -${{ github.event.pull_request.commits }} - - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} gbs | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" - + uses: ./.github/actions/check-rebuild + with: + mode: gbs - uses: actions/setup-python@v1 - name: prepare GBS diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index e0b199b..c44071c 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -13,14 +13,9 @@ jobs: with: fetch-depth: 0 - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} rebuild | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" + uses: ./.github/actions/check-rebuild + with: + mode: rebuild - uses: actions/setup-python@v4 with: python-version: "3.10" diff --git a/.github/workflows/pdebuild.yml b/.github/workflows/pdebuild.yml index 6a2dad2..a9ddd3a 100644 --- a/.github/workflows/pdebuild.yml +++ b/.github/workflows/pdebuild.yml @@ -46,14 +46,9 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: -${{ github.event.pull_request.commits }} - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} debian | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" + uses: ./.github/actions/check-rebuild + with: + mode: debian - uses: actions/setup-python@v1 - name: make cache dir for pbuilder diff --git a/.github/workflows/risc-v.yml b/.github/workflows/risc-v.yml index ade4eaa..6c48d95 100644 --- a/.github/workflows/risc-v.yml +++ b/.github/workflows/risc-v.yml @@ -13,14 +13,9 @@ jobs: with: fetch-depth: 0 - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} rebuild | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" + uses: ./.github/actions/check-rebuild + with: + mode: rebuild - uses: nnstreamer/run-on-arch-action@master name: Run commands if: env.rebuild == '1' diff --git a/.github/workflows/ubuntu_clean_llvm_build.yml b/.github/workflows/ubuntu_clean_llvm_build.yml index 153acf8..07af9e1 100644 --- a/.github/workflows/ubuntu_clean_llvm_build.yml +++ b/.github/workflows/ubuntu_clean_llvm_build.yml @@ -17,15 +17,11 @@ jobs: with: fetch-depth: 0 - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} rebuild | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" - - uses: actions/setup-python@v1 + uses: ./.github/actions/check-rebuild + with: + mode: rebuild + - if: env.rebuild == '1' + uses: actions/setup-python@v1 with: python-version: '3.x' - name: install minimal requirements diff --git a/.github/workflows/ubuntu_clean_meson_build.yml b/.github/workflows/ubuntu_clean_meson_build.yml index 4c4919e..ca36b9f 100644 --- a/.github/workflows/ubuntu_clean_meson_build.yml +++ b/.github/workflows/ubuntu_clean_meson_build.yml @@ -17,15 +17,11 @@ jobs: with: fetch-depth: 0 - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} rebuild | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" - - uses: actions/setup-python@v1 + uses: ./.github/actions/check-rebuild + with: + mode: rebuild + - if: env.rebuild == '1' + uses: actions/setup-python@v1 with: python-version: '3.x' - name: install requirements diff --git a/.github/workflows/yocto.yml b/.github/workflows/yocto.yml index ae5f817..70e712e 100644 --- a/.github/workflows/yocto.yml +++ b/.github/workflows/yocto.yml @@ -14,14 +14,9 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: -${{ github.event.pull_request.commits }} - name: Check if rebuild required - ## @todo This should become a reusable workflow. - run: | - tmpfile=$(mktemp) - git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile} - echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV" - rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} build | grep "REBUILD=YES" | wc -l` - echo "Rebuild required: ${rebuild}" - echo "rebuild=${rebuild}" >> "$GITHUB_ENV" + uses: ./.github/actions/check-rebuild + with: + mode: build ## @todo Make cache works (daily update cache on main branch / restore the cache on each PR (not saving)) - name: Prepare build if: env.rebuild == '1' -- 2.7.4