2023-01-25 19:22:11 +00:00
name : webapp
on :
push :
branches :
- 'main'
2023-02-11 00:51:37 +00:00
paths-ignore :
- 'docs/**'
- '.github/**'
2023-01-25 19:22:11 +00:00
pull_request :
branches :
- 'main'
2023-02-11 00:51:37 +00:00
paths-ignore :
- 'docs/**'
- '.github/**'
2023-01-25 19:22:11 +00:00
jobs :
decide-what-jobs-to-run :
runs-on : ubuntu-22.04
outputs :
test-style : ${{ steps.check-diffs.outputs.web-changed == '1' }}
test-generated-files : ${{ steps.check-diffs.outputs.web-changed == '1' && steps.check-main-push.outputs.is-main-push == '0'}}
update-generated-files : ${{ steps.check-diffs.outputs.web-changed == '1' && steps.check-main-push.outputs.is-main-push == '1'}}
steps :
- name : Get source
2024-03-04 14:45:37 +00:00
uses : actions/checkout@v4
2023-01-25 19:22:11 +00:00
with :
fetch-depth : 2 # >1 needed for merge base
- name : Check push-to-main
id : check-main-push
run : |
set -x # echo all executed commands to the terminal
if [ "$GITHUB_EVENT_NAME" = 'push' ] && [ "$GITHUB_REF_NAME" = 'main' ]; then
echo is-main-push=1 >> "$GITHUB_OUTPUT"
else
echo is-main-push=0 >> "$GITHUB_OUTPUT"
fi
- name : Check for diffs
id : check-diffs
run : |
set -x # echo all executed commands to the terminal
function get_changes() { # name, paths...
local name="$1"
shift
if [ "$GITHUB_EVENT_NAME" = 'push' ] && [ "$GITHUB_REF_NAME" = 'main' ]; then
DIFF_TARGET='--name-only HEAD^'
else
git fetch --depth=1 origin "$GITHUB_BASE_REF"
DIFF_TARGET="--merge-base origin/$GITHUB_BASE_REF"
fi
set +e # do not abort if git --exit-code returns nonzero
git diff --exit-code ${DIFF_TARGET} -- "$@"
echo "$name-changed=$?" >> "$GITHUB_OUTPUT"
}
get_changes web CMakeLists.txt web
code-style :
runs-on : ubuntu-latest
needs : [ decide-what-jobs-to-run ]
if : ${{ needs.decide-what-jobs-to-run.outputs.test-style == 'true' }}
steps :
- name : Get source
2024-03-04 14:45:37 +00:00
uses : actions/checkout@v4
2023-01-25 19:22:11 +00:00
- name : Get dependencies
run : |
set -e # abort if any command fails
2023-11-24 17:01:00 +00:00
sudo apt-get update
2023-01-25 19:22:11 +00:00
sudo apt-get install -y npm
- name : Check for style diffs
id : check-for-diffs
run : |
set -x # echo all executed commands to the terminal
set -e # abort if any command fails
npm --prefix web ci
npm --prefix web run lint:fix
set +e # do not end the script if a cmd returns an exit code
git diff --exit-code web > style.diff
echo "differs=$?" >> $GITHUB_OUTPUT
echo ===
cat style.diff
echo ===
set -e # undo set +e
- name : Upload diffs
2024-03-04 14:45:37 +00:00
uses : actions/upload-artifact@v4
2023-01-25 19:22:11 +00:00
if : ${{ steps.check-for-diffs.outputs.differs == '1' }}
with :
name : code-style.diff
path : 'style.diff'
- name : Fail if diffs exist
if : ${{ steps.check-for-diffs.outputs.differs == '1' }}
run : |
echo "code style does not match expected."
cat style.diff
echo "When CI is done, the above patch will be uploaded as 'code-style.diff' to https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/ ."
exit 1
test-generated-files :
runs-on : ubuntu-latest
needs : [ decide-what-jobs-to-run ]
if : ${{ needs.decide-what-jobs-to-run.outputs.test-generated-files == 'true' }}
steps :
- name : Get source
2024-03-04 14:45:37 +00:00
uses : actions/checkout@v4
2023-01-25 19:22:11 +00:00
with :
fetch-depth : 2 # >1 needed for merge base
- name : Check for changes to generated files
run : |
git fetch --quiet --depth=1 origin "$GITHUB_BASE_REF"
set -e # abort if diff --exit-code fails
echo
echo Hello, code contributor!
echo For security reasons, ${GITHUB_REPOSITORY} does not accept PRs that change generated files.
echo
echo Please undo your changes to these files :
git diff --exit-code --name-only --merge-base "origin/$GITHUB_BASE_REF" -- \
2024-10-28 20:45:29 +00:00
web/package.json.buildonly \
2023-11-28 01:23:40 +00:00
web/public_html/transmission-app.css \
web/public_html/transmission-app.css.LEGAL.txt \
web/public_html/transmission-app.css.map \
2023-01-25 19:22:11 +00:00
web/public_html/transmission-app.js \
2023-11-28 01:23:40 +00:00
web/public_html/transmission-app.js.LEGAL.txt \
web/public_html/transmission-app.js.map
2023-01-25 19:22:11 +00:00
update-generated-files :
runs-on : ubuntu-latest
needs : [ decide-what-jobs-to-run ]
if : ${{ needs.decide-what-jobs-to-run.outputs.update-generated-files == 'true' }}
steps :
- name : Show env
run : |
env | sort
- name : Get dependencies
run : |
set -e # abort if any command fails
sudo apt-get install -y npm
- name : Get source
2024-03-04 14:45:37 +00:00
uses : actions/checkout@v4
2023-01-25 19:22:11 +00:00
with :
fetch-depth : 2 # >1 needed for merge base
- name : Generate webapp files
run : |
set -x # echo all executed commands to the terminal
set -e # abort if any command fails
npm --prefix web ci
npm --prefix web run build
2024-10-28 20:45:29 +00:00
npm --prefix web run generate-buildonly
2023-01-25 19:22:11 +00:00
git diff --name-only
git add --update web
- name : Create pull request
2024-03-04 14:45:37 +00:00
uses : peter-evans/create-pull-request@v6
2023-01-25 19:22:11 +00:00
with :
branch : 'chore/update-webapp-files'
commit-message: 'chore : update generated transmission-web files'
delete-branch : true
title: 'chore : update generated transmission-web files'
body : Generated from https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}