GitHub Actions π
Formatting
-
Add a line break between each root-level block.
name: Build on: push env: DOCKER_IMAGE: $
name: Build on: push env: DOCKER_IMAGE: $
-
Add a line break between each job step.
steps: - uses: actions/[email protected] - name: Login to DockerHub uses: docker/[email protected]
steps: - uses: actions/[email protected] - name: Login to DockerHub uses: docker/[email protected]
Naming
-
Name workflow files following the pattern
verb_environment.yml
.environment
can be omitted if the workflow does not vary per environment.βββ ci.yml βββ run_all_tests.yml βββ prod_deploy.yml βββ docker_test.yml
βββ test.yml βββ deploy.yml βββ deploy_production.yml βββ deploy_staging.yml βββ test_docker_build.yml
-
The name attribute for job must be provided as this is the value which will be used in the web UI.
jobs: publish: runs-on: ubuntu-latest
jobs: publish: name: Publish Docker Image runs-on: ubuntu-latest
-
The name attribute jobs set must be provided and follow the pattern βVerb descriptionβ. Start with a verb so there is a clear expectation of what the step is for.
- run: echo "SEGMENT_JS_KEY=$SEGMENT_JS_KEY" >> .env - uses: docker/[email protected]
- name: Add environments variables to .env file run: echo "SEGMENT_JS_KEY=$SEGMENT_JS_KEY" >> .env - name: Login to DockerHub uses: docker/[email protected]
Syntax
-
In the step block with
run
, prefer using a command with single line format.- name: All using commands run: | echo "command no.1" >> .env
- name: All using commands run: echo "command no.1" >> .env
And for multi-line commands, prefer using the literal block scalar
|
which preserves new lines and trailing spaces.- name: All using commands run: | echo "command no.1" >> .env echo "command no.2" >> .env echo "command no.3" >> .env
Timeout
-
Prefer to set a timeout for each job.
jobs: build: name: Publish Docker Image runs-on: ubuntu-latest ... publish: name: Publish Docker Image runs-on: ubuntu-latest ...
jobs: build: name: Publish Docker Image runs-on: ubuntu-latest timeout-minutes: 10 ... publish: name: Publish Docker Image runs-on: ubuntu-latest timeout-minutes: 5 ...