The solutions for exercise08 of Missingsemester(2020)
Lecture 08. Metaprogramming
Most makefiles provide a target called
clean
. This isn’t intended to produce a file calledclean
, but instead to clean up any files that can be re-built by make. Think of it as a way to “undo” all of the build steps. Implement aclean
target for thepaper.pdf
Makefile
above. You will have to make the target phony. You may find thegit ls-files
subcommand useful. A number of other very common make targets are listed here.
If you check the files in the folder after we run make
, you will find that the new files are paper.aux
, paper.log
, paper.pdf
and paper.png
. These files are what we want to clean
. In order to do this, we can modify Makefile
like this ⬇️
paper.pdf: paper.tex plot-data.png
pdflatex paper.tex
plot-%.png: %.dat plot.py
./plot.py -i $*.dat -o $@
.PHONY: clean
cleanall: cleanaux cleanlog cleanpdf cleanpng
cleanaux:
rm *.aux
cleanlog:
rm *.log
cleanpdf:
rm *.pdf
cleanpng:
rm *.png
Take a look at the various ways to specify version requirements for dependencies in Rust’s build system. Most package repositories support similar syntax. For each one (caret, tilde, wildcard, comparison, and multiple), try to come up with a use-case in which that particular kind of requirement makes sense.
- Caret requirements: It is used to update minor version and patch version.
- Tilde requirements: It is used to match the most recent patch version by freezing major version and minor version.
- Wildcard requirements: It is used to specify major version and accept any minor version and patch version.
- Both of comparison requirements and multiple requirements are used to give more control over packages. We may used them to overcome conflicts.
Git can act as a simple CI system all by itself. In
.git/hooks
inside any git repository, you will find (currently inactive) files that are run as scripts when a particular action happens. Write apre-commit
hook that runsmake paper.pdf
and refuses the commit if themake
command fails. This should prevent any commit from having an unbuildable version of the paper.
After reading this tutorial above, You will find how git hooks work. So the solution will be ⬇️
-
Write a
pre-commit
hook in whatever languages you like. Here is my scipt.#!/usr/bin/env bash if ! make paper.pdf; then echo "==> Running make command fail :(" exit 1 else echo "==> Running make command successfully :)" exit 0 fi
-
Change the file mode of hook you just wrote, make it executable. Type
chmod u+x pre-commit
in your terminal. -
mv the hook to
.git/hooks
. Typemv pre-commit .git/hooks/pre-commit
Now it time to test if your hook works as you expected 🤗 ⬇️
> git add .
> git commit -m "Try to commit"
Set up a simple auto-published page using GitHub Pages. Add a GitHub Action to the repository to run
shellcheck
on any shell files in that repository (here is one way to do it). Check that it works!
This blog is host by Github Pages🤗
-
First, create a
yml
file in your.github/workflows/
. Myyml
file looks like:on: [push] name: 'Trigger: Push action' jobs: shellcheck: name: Shellcheck runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Run ShellCheck uses: ludeeus/action-shellcheck@master
-
git add
&&git commit -m ""
&&git push
. Add your workflow to your remote repo. -
Now we can create a simple
.sh
file. I deliberately didn’t addshebang
insh
file.date
If you run
shellcheck
in your local machine, you should get a warning says:SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
-
git add
&&git commit -m ""
&&git push
. Check if your workflow works by clickingActions
in your repo. You will see it didn’t pass the test. The output is:Run ludeeus/action-shellcheck@master Run problem_matcher_file="/home/runner/work/_actions/ludeeus/action-shellcheck/master/.github/problem-matcher-gcc.json" Run if [[ "Linux" == "macOS" ]]; then Run "/home/runner/work/_actions/ludeeus/action-shellcheck/master/shellcheck" --version ShellCheck - shell script analysis tool version: 0.8.0 license: GNU General Public License, version 3 website: https://www.shellcheck.net Run declare -a options Run declare -a excludes Run declare -a files Run declare -a filepaths Run statuscode=0 Error: ./another.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. [SC2148] Error: ./sample.sh:1:1: error: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. [SC2148] Run echo "Files: ./another.sh ./sample.sh" Files: ./another.sh ./sample.sh Excluded: ! -path *./.git/* ! -path *.go ! -path */mvnw Options: --format=gcc Status code: 1 Error: Process completed with exit code 1.
Build your own GitHub action to run
proselint
orwrite-good
on all the.md
files in the repository. Enable it in your repository, and check that it works by filing a pull request with a typo in it.
I should learn some basics of docker
, then I may return to this exercise :(