fix(ci): release upload assets incorrect #60
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- edited | |
permissions: | |
contents: read | |
pull-requests: write | |
issues: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
pre-test: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
need_to_run: ${{ steps.set-matrix.outputs.need_to_run }} | |
steps: | |
- name: generate matrix from PR body | |
id: set-matrix | |
env: | |
RAW_BODY: ${{ github.event.pull_request.body }} | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
script: | | |
const TASK_REGEXP = /- \[x\] (.*)/g; | |
const getTask = (text) => { | |
const result = []; | |
let match; | |
while ((match = TASK_REGEXP.exec(text)) !== null) { | |
result.push(match[1]); | |
} | |
return { | |
matrix: result, | |
need_to_run: result.length > 0 | |
}; | |
} | |
if (context.payload.action !== "edited") { | |
console.log("not edited event"); | |
const { matrix, need_to_run } = getTask(process.env.RAW_BODY); | |
core.setOutput("matrix", matrix); | |
core.setOutput("need_to_run", need_to_run); | |
return; | |
} | |
const query = `query ($owner: String!, $name: String!, $number: Int!) { | |
repository(owner: $owner, name: $name) { | |
pullRequest(number: $number) { | |
userContentEdits(first: 2) { | |
nodes { | |
diff | |
} | |
} | |
} | |
} | |
}`; | |
const variables = { | |
owner: context.repo.owner, | |
name: context.repo.repo, | |
number: context.issue.number | |
}; | |
const history = await github.graphql(query, variables); | |
if (history.repository.pullRequest.userContentEdits.nodes.length !== 2) { | |
console.log("not enough history") | |
const { matrix, need_to_run } = getTask(process.env.RAW_BODY); | |
core.setOutput("matrix", matrix); | |
core.setOutput("need_to_run", need_to_run); | |
return; | |
} | |
const latestTasks = getTask(history.repository.pullRequest.userContentEdits.nodes[0].diff); | |
const previousTasks = getTask(history.repository.pullRequest.userContentEdits.nodes[1].diff); | |
const sortLatest = latestTasks.matrix.sort(); | |
const sortPrevious = previousTasks.matrix.sort(); | |
for (const [index, task] of sortPrevious.entries()) { | |
if (sortLatest[index] === undefined) { | |
console.log("latest task is less than previous, skip"); | |
continue; | |
} | |
if (task !== sortLatest[index]) { | |
console.log(`has added ${task}, need to run`); | |
const { matrix, need_to_run } = latestTasks; | |
core.setOutput("matrix", matrix); | |
core.setOutput("need_to_run", need_to_run); | |
return; | |
} | |
} | |
console.log("no new task added, skip"); | |
core.setOutput("matrix", []); | |
core.setOutput("need_to_run", false); | |
test: | |
runs-on: ubuntu-latest | |
needs: pre-test | |
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }} | |
outputs: | |
matrix: ${{ needs.pre-test.outputs.matrix }} | |
strategy: | |
fail-fast: true | |
matrix: | |
target-arch: ${{ fromJSON(needs.pre-test.outputs.matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Update kernel submodules | |
if: ${{ startsWith(matrix.target-arch, 'kernel') }} | |
run: git submodule update --init kernel | |
- name: Update buildroot submodules | |
if: ${{ !startsWith(matrix.target-arch, 'kernel') }} | |
run: git submodule update --init buildroot | |
- name: Install deps | |
run: sudo apt-get install -y build-essential flex bison libssl-dev libelf-dev bc | |
- name: Install kernel arm64 deps | |
if: ${{ matrix.target-arch == 'kernel-arm64' }} | |
run: sudo apt-get install -y gcc-aarch64-linux-gnu | |
- name: Defconfig | |
run: make defconfig-${{ matrix.target-arch }} | |
- name: Build | |
run: make build-${{ matrix.target-arch }} -j$(nproc) | |
- name: Get output file size | |
run: | | |
FILE_PATH=$(make print-outpath-${{ matrix.target-arch }}) | |
SIZE_B=$(stat -c%s "$FILE_PATH") | |
SIZE_MB=$(echo $SIZE_B | awk '{ printf "%.4f", $1 / 1024 / 1024 }') | |
mkdir outputs-size | |
echo "${{ matrix.target-arch }} $SIZE_MB $SIZE_B" > outputs-size/${{ matrix.target-arch }}.txt | |
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 | |
with: | |
name: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.target-arch }} | |
path: outputs-size/*.txt | |
retention-days: 1 | |
post-test: | |
runs-on: ubuntu-latest | |
needs: | |
- pre-test | |
- test | |
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }} | |
steps: | |
- name: Load outputs-size | |
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2 | |
with: | |
pattern: ${{ github.run_id }}-${{ github.run_number }}-* | |
path: outputs-size | |
merge-multiple: true | |
- name: Format outputs-size | |
id: size | |
run: | | |
cat > comment.md <<EOF | |
Build Output Summary | |
|Target|Size| | |
|-|-| | |
`sort outputs-size/*.txt | awk '{ printf "|**"$1"**|*"$2"MB ("$3" bytes)*|\n" }'` | |
EOF | |
- name: Find comment | |
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3.0.0 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: Build Output Summary | |
- name: Create or update comment | |
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: ./comment.md | |
edit-mode: replace |