From 4fb2b63d0c13dc5d291fccb80bf5389326ba79c8 Mon Sep 17 00:00:00 2001 From: Youjie Zheng Date: Sat, 19 Oct 2024 18:44:48 +0800 Subject: [PATCH] [CI] Abstarct an independent action to checkout and patch --- .github/workflows/actions/checkout/action.yml | 31 ++++++++++++++++++ .github/workflows/build.yml | 32 +++++-------------- .github/workflows/test.yml | 32 +++++-------------- 3 files changed, 47 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/actions/checkout/action.yml diff --git a/.github/workflows/actions/checkout/action.yml b/.github/workflows/actions/checkout/action.yml new file mode 100644 index 0000000000..7c217ace0c --- /dev/null +++ b/.github/workflows/actions/checkout/action.yml @@ -0,0 +1,31 @@ +name: Checkout repo and patch dependencies + +inputs: + package: + description: 'The package that triggers the external test' + required: true + type: string + main-repo: + description: 'The main repository that runs the test' + required: true + type: string + main-ref: + description: 'The branch of the main repository' + required: false + default: 'main' + type: string + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.main-repo }} + ref: ${{ inputs.main-ref }} + - name: Patch for the commit to be tested + run: | + cargo install dependencies-patch + dependencies-patch -c . \ + -n ${{ inputs.package }} \ + -t git --git-repo ${{ github.repository }} \ + --commit ${{ github.sha }} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a613785b9..7004db2d0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,20 +29,12 @@ jobs: RUSTUP_TOOLCHAIN: ${{ matrix.rust-toolchain }} steps: - uses: actions/checkout@v4 - if: inputs.package == '' - - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/checkout if: inputs.package != '' with: - repository: ${{ env.prj-repo }} - ref: ${{ inputs.ref }} - - name: Patch for the commit to be tested - if: inputs.package != '' - run: | - cargo install dependencies-patch - dependencies-patch -c . \ - -n ${{ inputs.package }} \ - -t git --git-repo ${{ github.repository }} \ - --commit ${{ github.sha }} + caller-package: ${{ inputs.package }} + main-repo: ${{ env.prj-repo }} + main-ref: ${{ inputs.ref }} - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust-toolchain }} @@ -78,20 +70,12 @@ jobs: RUSTUP_TOOLCHAIN: ${{ matrix.rust-toolchain }} steps: - uses: actions/checkout@v4 - if: inputs.package == '' - - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/checkout if: inputs.package != '' with: - repository: ${{ env.prj-repo }} - ref: ${{ inputs.ref }} - - name: Patch for the commit to be tested - if: inputs.package != '' - run: | - cargo install dependencies-patch - dependencies-patch -c . \ - -n ${{ inputs.package }} \ - -t git --git-repo ${{ github.repository }} \ - --commit ${{ github.sha }} + caller-package: ${{ inputs.package }} + main-repo: ${{ env.prj-repo }} + main-ref: ${{ inputs.ref }} - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust-toolchain }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3c7a15a61..c3562e8c19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,20 +26,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - if: inputs.package == '' - - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/checkout if: inputs.package != '' with: - repository: ${{ env.prj-repo }} - ref: ${{ inputs.ref }} - - name: Patch for the commit to be tested - if: inputs.package != '' - run: | - cargo install dependencies-patch - dependencies-patch -c . \ - -n ${{ inputs.package }} \ - -t git --git-repo ${{ github.repository }} \ - --commit ${{ github.sha }} + caller-package: ${{ inputs.package }} + main-repo: ${{ env.prj-repo }} + main-ref: ${{ inputs.ref }} - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ env.rust-toolchain }} @@ -56,20 +48,12 @@ jobs: arch: [x86_64, riscv64, aarch64] steps: - uses: actions/checkout@v4 - if: inputs.package == '' - - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/checkout if: inputs.package != '' with: - repository: ${{ env.prj-repo }} - ref: ${{ inputs.ref }} - - name: Patch for the commit to be tested - if: inputs.package != '' - run: | - cargo install dependencies-patch - dependencies-patch -c . \ - -n ${{ inputs.package }} \ - -t git --git-repo ${{ github.repository }} \ - --commit ${{ github.sha }} + caller-package: ${{ inputs.package }} + main-repo: ${{ env.prj-repo }} + main-ref: ${{ inputs.ref }} - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ env.rust-toolchain }}