Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bekcpear/d1e81d620bb8450616e83f863aed8564 to your computer and use it in GitHub Desktop.
Save bekcpear/d1e81d620bb8450616e83f863aed8564 to your computer and use it in GitHub Desktop.
# @bekcpear
name: repoman
on:
pull_request_target:
branches:
- master
paths-ignore:
- '.github/**'
- 'metadata/**'
types: [opened, reopened, synchronize]
jobs:
check-changed-ebuilds:
name: check changed ebuilds
runs-on: ubuntu-20.04
permissions:
contents: read
pull-requests: write
steps:
- name: Setup python3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Prepare environment
shell: bash
run: |
set -xe
python -V
python -VV
sudo mkdir -m 777 -p /etc/portage
sudo mkdir -m 777 -p /var/db/repos/gentoo{,-zh}
sudo mkdir -m 777 -p /var/tmp/portage
- name: Install dependencies
run: sudo apt-get install -y --no-install-recommends libxslt-dev libxml2-dev libxml2-utils zstd python3-lxml jq
- name: Fetch portage
uses: actions/checkout@v2
with:
repository: gentoo/portage
- name: Install portage
shell: bash
run: |
set -xe
printf "[build_ext]\nportage-ext-modules=true" >>setup.cfg
sudo ./setup.py install
sudo useradd portage -d /var/tmp/portage -s /bin/false
sudo ln -s /var/db/repos/gentoo/profiles/default/linux/amd64/17.1 /etc/portage/make.profile
sudo printf "[gentoo-zh]\nlocation = /var/db/repos/gentoo-zh" >>/etc/portage/repos.conf
- name: Install repoman
shell: bash
run: |
set -xe
cd repoman
sudo ./setup.py install
sudo mv /usr/local/share/repoman /usr/share/ || true
- name: Checkout the head ref of the pull request
uses: actions/checkout@v2
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: gentoo-zh
- name: Fetch ::gentoo repo
uses: actions/checkout@v2
with:
repository: gentoo-mirror/gentoo
path: gentoo
- name: Get the base commit
id: basecommit
shell: bash
env:
COMMITS_URL: ${{ github.event.pull_request.commits_url }}
COMMITS_JSON: /tmp/commits.json
run: |
set -xe
curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o ${COMMITS_JSON} ${COMMITS_URL}
[[ $(file --mime-type ${COMMITS_JSON}) =~ application/json$ ]]
<${COMMITS_JSON} jq '.message' && false || true
commits=( $(<${COMMITS_JSON} jq '.[].sha' | cut -d'"' -f2) )
pcommits=( $(<${COMMITS_JSON} jq '.[].parents[].sha' | cut -d'"' -f2) )
sha=${pcommits[0]}
for pcommit in ${pcommits[@]}; do
pcommit_not_matched=0
for commit in ${commits[@]}; do
if [[ ${pcommit} == ${commit} ]]; then
pcommit_not_matched=1
fi
done
if [[ ${pcommit_not_matched} == 0 ]]; then
sha=${pcommit}
break
fi
done
echo "::set-output name=sha::${sha}"
- name: Check
id: check
shell: bash
env:
THEBASEREF: ${{ steps.basecommit.outputs.sha }}
run: |
set -e
sudo mv ${{ github.workspace }}/gentoo{,-zh} /var/db/repos/
cd /var/db/repos/gentoo-zh
echo "git diff --raw ${THEBASEREF}"
git diff --raw ${THEBASEREF}
diff_files=$(git diff --raw --name-only ${THEBASEREF})
cates=$(cat /var/db/repos/gentoo{,-zh}/profiles/categories | sort -du)
declare -a check_pkgs
for file in ${diff_files}; do
c=${file%%/*}
for cate in ${cates}; do
if [[ ${c} == ${cate} ]]; then
n=${file#*/}
n=${n%%/*}
check_pkgs+=( ${c}/${n} )
fi
done
done
check_pkgs=( $(echo "${check_pkgs[@]}" | tr ' ' '\n' | sort -du | tr '\n' ' ') )
echo -n >/tmp/report.txt
ret=0
echo "pkgs: ${check_pkgs[@]}"
for pkg in ${check_pkgs[@]}; do
[[ -d ${pkg} ]] || continue
echo
echo "================================="
echo ">>> Checking ${pkg} ..."
echo "================================="
pushd ${pkg}
echo "=== Package: ${pkg} ===" >>/tmp/report.txt
repoman full -q > >(tee -ai /tmp/report.txt) || ret=1
echo >>/tmp/report.txt
popd
done
cd /var/db/repos/gentoo || true
v_repoman=$(repoman --version) || true
commit_gentoo=$(git rev-list -n1 HEAD) || true
report="$(cat /tmp/report.txt)"
report="${report//'%'/'%25'}"
report="${report//$'\n'/'%0A'}"
report="${report//$'\r'/'%0D'}"
echo "::set-output name=report::${report}"
echo "::set-output name=vrepoman::${v_repoman:-<None>}"
echo "::set-output name=gentoocommit::${commit_gentoo:-<None>}"
echo "::set-output name=qaopen::open"
echo "::set-output name=qakeywords::[:mag: QA Keywords Explanation](https://dev.gentoo.org/~zmedico/portage/doc/man/repoman.1.html#lbAG)"
if [[ ${ret} == 0 ]]; then
if ! egrep -v 'No QA issues found|^=== Package:.*|^[[:space:]]*$' /tmp/report.txt &>/dev/null; then
echo "::set-output name=state::passed"
echo "::set-output name=stateicon::heavy_check_mark"
echo "::set-output name=qaopen:: "
echo "::set-output name=qakeywords:: "
else
echo "::set-output name=state::passed with non-fatal QA errors"
echo "::set-output name=stateicon::white_circle"
fi
else
echo "::set-output name=state::failed"
echo "::set-output name=stateicon::x"
exit 1
fi
- name: Hide previous results
if: ${{ always() }}
shell: bash
env:
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
COMMENTS_JSON: /tmp/comments.json
run: |
curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o ${COMMENTS_JSON} ${COMMENTS_URL}
node_ids=( $(<${COMMENTS_JSON} jq '.[] | select(.body|test("^##\\s*[a-zA-Z_:]+\\s*repoman\\s*checks")) | select(.user.id == 41898282) | .node_id' | cut -d'"' -f2) )
echo "${node_ids[@]}"
json="{ \"query\": \"mutation {
minimizeComment(input: {
subjectId: \\\"NODEID\\\",
classifier: OUTDATED
}) {
clientMutationId,
minimizedComment {
isMinimized,
minimizedReason,
viewerCanMinimize
}
}
}\"
}"
json=$(tr -d '\n' <<<${json})
for node_id in ${node_ids[@]}; do
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "${json/NODEID/${node_id}}" \
https://api.github.com/graphql
done
- name: Post result
if: ${{ always() && steps.check.outputs.report }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.number }}
body: |
## :${{steps.check.outputs.stateicon}}: repoman checks ${{steps.check.outputs.state}}
_${{ steps.check.outputs.vrepoman }}_
_::gentoo_ repo latest commit: https://github.com/gentoo-mirror/gentoo/commit/${{ steps.check.outputs.gentoocommit }}
<details ${{ steps.check.outputs.qaopen }}>
<summary>QA Result:</summary>
```
${{ steps.check.outputs.report }}
```
</details>
${{ steps.check.outputs.qakeywords }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment