Write cleaner and more maintainable CI/CD workflows by following established syntax patterns and best practices. Use GitHub Actions’ built-in features like working-directory
instead of manual directory changes, employ proper shell quoting and efficient commands, and prefer single-line commands when appropriate.
Key practices:
working-directory
parameter instead of cd
commands in run steps"$variable"
) and use efficient command alternatives (tar -xz -C
instead of --directory=
)mkdir -p
to handle existing directories gracefullyExample improvements:
# Instead of:
- name: Build WASM Library
run: |
cd lib/binding_web
npm ci
npm run build:debug
# Use:
- name: Build WASM Library
working-directory: lib/binding_web
run: npm ci && npm run build:debug
# Instead of:
- run: |
echo "DOCKER_CMD=docker run --rm -v /home/runner:/home/runner -w . $CROSS_IMAGE" >> $GITHUB_ENV
# Use:
- run: echo "DOCKER_CMD=docker run --rm -v /home/runner:/home/runner -w . $CROSS_IMAGE" >> $GITHUB_ENV
These optimizations improve readability, reduce potential errors, and make workflows more maintainable while following GitHub Actions conventions.
Enter the URL of a public GitHub repository