GitHub Actions, Pages, releases and security features
Automate tests with a GitHub Actions workflow, publish a free website with GitHub Pages, tag versions and publish releases, and switch on Dependabot, secret scanning and code scanning.
Key ideas
How it works
1. Your first workflow: test every pull request
name: tests
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -r requirements.txt
- run: pytest -q- Commit the file; the Actions tab shows each run and its logs.
- Make the check required for main in your ruleset, so failing code cannot be merged.
- Store keys in and use them as
${{ secrets.API_KEY }}. - Pin actions to a version (or a commit SHA for third-party actions) and give workflows the least permissions they need.
2. Publish a website with GitHub Pages
- Put your site files (index.html and assets) in the repository, or build them with a workflow.
- Open . Under Build and deployment, choose Deploy from a branch (main, root or /docs) or GitHub Actions.
- Wait a minute and open
https://username.github.io/repository/. - For your own domain, add it under Custom domain, create the DNS records your registrar needs, and tick Enforce HTTPS.
3. Tags and releases
$ git tag -a v1.0 -m "First complete set of notes"
$ git tag
v1.0
$ git show v1.0 --stat --format='%h %s'
tag v1.0
Tagger: Asha Learner <[email protected]>
First complete set of notes
1ee8249 Revert "Add a wrong fact"
glossary.md | 1 -
1 file changed, 1 deletion(-)
$ git push -q origin v1.0 && git ls-remote --tags origin
2ff02f39305b4137f405602cad721c3958d0c5e1 refs/tags/v1.0
1ee824981be5f41fefe948779fa71284523eb144 refs/tags/v1.0^{}On GitHub open Releases, then Draft a new release, pick the tag, and select Generate release notes to list merged pull requests automatically. Use semantic versions: v1.4.2 means major.minor.patch.
4. Security features to switch on
| Feature | What it does | Where |
|---|---|---|
| Dependabot alerts and updates | Warns about vulnerable dependencies and opens update PRs | Settings, Code security |
| Secret scanning and push protection | Finds committed tokens and blocks pushes with known secret patterns | Settings, Code security |
| Code scanning (CodeQL) | Finds security bugs in your code on every PR | Security tab, Code scanning |
| Security policy | SECURITY.md tells people how to report vulnerabilities | Repository root or .github/ |
5. Codespaces: a computer in the browser
Press . on a repository for a quick web editor, or open Code, Codespaces for a full cloud development environment with a terminal. A .devcontainer/devcontainer.json file sets up the same tools for everyone. Free personal usage is limited each month, so stop codespaces you are not using.
Common mistakes and fixes
| Mistake | Fix |
|---|---|
| Printing secrets in workflow logs | Use secrets, never echo them, and keep workflow permissions minimal. |
| Using unpinned third-party actions | Pin to a version or a full commit SHA. |
| Expecting Pages to run a server or database | Pages hosts static files only; use another service for back-end code. |
Practice
- Add the tests workflow to a small Python project and make it fail, then pass.
- Publish a one-page portfolio with GitHub Pages.
- Turn on Dependabot alerts and secret scanning for your repositories.
Quick check
Where do workflow files live?
.github/workflows/ in the repository, as YAML files.
How do you stop failing code from being merged?
Make the workflow's status check required in the ruleset or branch protection for main.
What does push protection do?
Blocks pushes that contain known secret formats, such as API tokens.