Skip to content

Reconversion

Reconversion #294

Workflow file for this run

name: "⚔ check"
on:
## Note that 'pull_request' workflows can't have permission to write
## to PRs from forked repositry. So we use a separate workflow to
## comment on the PR. Documentation for that:
## https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
pull_request:
types: [opened, synchronize]
jobs:
get-pr-number:
runs-on: ubuntu-latest
steps:
- name: Get PR number
env:
PR_NUMBER: ${{ github.event.number }}
run: |
mkdir -p .reports
echo "$PR_NUMBER" > .reports/pr
- name: ⬆ Store PR number
uses: actions/upload-artifact@v3
if: always()
with:
name: check-report
path: .reports
check-translation:
runs-on: ubuntu-latest
env:
REPORT_PATH: .reports/translation
steps:
- uses: actions/checkout@v2
- name: 🚚 Install dependencies
run: |
git fetch --unshallow --tags &&
npm install &&
sudo apt install gettext
- name: ⚔ Check translation file
id: translation
run: |
mkdir -p "$REPORT_PATH"
REPORT_FILE=$REPORT_PATH/report
npm run gettext:extract
if out=$(git diff --exit-code -- src/i18n/); then
echo '### ✔️ translation is up-to-date' > "$REPORT_FILE"
exit 0
fi
echo "=== raw diff output ==="
echo "$out"
echo "======================="
comment_diff=$(echo "$out" |
egrep -v '^(---|\+\+\+) ' |
egrep '^(\+|-)' |
egrep -v '^(\+|-)#: ') || true
if [ -z "$comment_diff" ]; then
comment_diff=$(git diff -- src/i18n/fr-FR/ |
egrep -v '^(---|\+\+\+) ' |
egrep '^(\+|-)' |
egrep '^\+#: ' |
cut -f 2 -d " " |
cut -f 1 -d ":" |
sort |
uniq -c)
message='PO file needs a simple update (no fuzzy entries found). '
message+='Please run the command \`npm run gettext:extract\` '
message+='before pushing the code to ensure that all necessary '
message+='translations are included and the PO file is up-to-date.'
else
message='Found missing translations. Please run the command \`npm '
message+='run gettext:extract\` before pushing the code to ensure '
message+='that all necessary translations are included.'
fi
short_stat=$(git diff --shortstat -- src/i18n/)
cat <<EOF > "$REPORT_FILE"
### :x: translation needs update
<p>
$message
</p>
<details>
<summary>$short_stat</summary>
<p>
\`\`\`diff
$comment_diff
\`\`\`
</p>
</details>
EOF
exit 1
- name: ⬆ Store translation report
uses: actions/upload-artifact@v3
if: always()
with:
name: check-report
path: .reports
check-prettierx:
runs-on: ubuntu-latest
env:
REPORT_PATH: .reports/prettierx
steps:
- uses: actions/checkout@v2
- name: 🚚 Install dependencies
run: |
git fetch --unshallow --tags &&
npm install &&
git clone https://github.com/0k/prettierx &&
cd prettierx &&
npm install
- name: ⚔ Check prettierx
id: linter
run: |
mkdir -p "$REPORT_PATH"
REPORT_FILE="$REPORT_PATH/report"
prettierx/bin/prettierx.js -w src/
if out=$(git diff --exit-code -- src/); then
echo '### ✔️ code style matches our guidelines' > "$REPORT_FILE"
exit 0
fi
echo "=== raw diff output ==="
echo "$out"
echo "======================="
short_stat=$(git diff --shortstat -- src)
cat <<EOF > "$REPORT_FILE"
### :x: code style needs update
It seems your code wasn't properly formatted using our current rules.
Please run `npx prettierx -w src/` on your code before submitting the
PR. You can amend this current PR.
<details>
<summary>$short_stat</summary>
<p>
\`\`\`diff
$out
\`\`\`
</p>
</details>
EOF
exit 1
- name: ⬆ Store translation report
uses: actions/upload-artifact@v3
if: always()
with:
name: check-report
path: .reports
report-metrics:
needs: [check-translation, check-prettierx]
runs-on: ubuntu-latest
steps:
- name: 🚚 Check out code for ${{ github.base_ref }}
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: 🚚 Install dependencies for ${{ github.base_ref }}
run: |
git fetch --unshallow --tags &&
npm install
- name: 🔍Gather data for ${{ github.base_ref }}
run: |
npm run build
mkdir -p .reports/{du,eslint}
report=".reports/du/${{ github.base_ref }}"
echo "Writing to '$report'."
(
cd dist &&
du -sbc js/*.js css/*.css \
> ../"$report"
) || true
tail -n 1 "$report" |
cut -f 1 -d " " \
> "$report".total
## remove the last line of the file
sed -i '$d' "$report"
report=".reports/eslint/${{ github.base_ref }}"
echo "Writing to '$report'."
npx eslint --format unix -- src/ \
> "$report" || true
tail -n 1 "$report" |
cut -f 1 -d " " \
> "$report".total
## remove the 2 last lines of the file.
sed -i 'N;$!P;$!D;$d' "$report"
- name: 🚚 Check out code for ${{ github.head_ref }}
uses: actions/checkout@v3
with:
clean: false
- name: 🚚 Install dependencies for ${{ github.head_ref }}
run: |
git fetch --unshallow --tags &&
rm -rf node_modules &&
npm install
- name: 🔍Gather data for ${{ github.head_ref }}
run: |
rm -rf build
npm run build
report=".reports/du/${{ github.head_ref }}"
echo "Writing to '$report'."
(
cd dist &&
du -sbc js/*.js css/*.css \
> ../"$report"
) || true
tail -n 1 "$report" |
cut -f 1 -d " " \
> "$report".total
## remove the last line of the file
sed -i '$d' "$report"
report=".reports/eslint/${{ github.head_ref }}"
echo "Writing to '$report'."
npx eslint --format unix -- src/ \
> "$report" || true
tail -n 1 "$report" |
cut -f 1 -d " " \
> "$report".total
## remove the 2 last lines of the file
sed -i 'N;$!P;$!D;$d' "$report"
- name: 📃 Report
id: metrics
run: |
cd .reports
mkdir -p reports
##
## du
##
out=$(
cd du
diff -u ${{ github.base_ref }} \
${{ github.head_ref }} | \
grep -E '^(\+|-)' | \
grep -vE '^(\+\+\+|---)' ||
true
)
if [ -z "$out" ]; then
cat <<EOF
<p>No package files changes detected (current size: $(
cat "du/${{ github.head_ref }}.total" |
numfmt --to=iec --format %.3fB
))</p>
EOF
else
cat <<EOF
<details>
<summary>Bundle size analysis</summary>
<p>
\`\`\`diff
$out
\`\`\`
</p>
</details>
EOF
fi > "reports/du"
##
## eslint
##
out=$(
cd eslint
diff -u ${{ github.base_ref }} \
${{ github.head_ref }} | \
grep -E '^(\+|-)' | \
grep -vE '^(\+\+\+|---)' ||
true
)
if [ -z "$out" ]; then
cat <<EOF
<p>No eslint changes detected ($(cat "eslint/${{ github.head_ref }}.total") issues reported)</p>
EOF
else
cat <<EOF
<details>
<summary>Eslint analysis</summary>
<p>
\`\`\`diff
$out
\`\`\`
</p>
</details>
EOF
fi > "reports/eslint"
##
## Final report
##
cat <<EOF > reports/report
### :page_with_curl: Metrics report
$(cat reports/{du,eslint})
EOF
- name: ⬆ Store report
uses: actions/upload-artifact@v3
if: always()
with:
name: check-report
path: .reports