BM: Baca dalam Bahasa Melayu
World 7: Robots: Actions & CI/CD
Secrets, variables, environments
You will learn: where to keep keys and settings, so workflows can use them safely.
The problem
Your deploy needs a Cloudflare token. Paste it into ci.yml? Anyone who can read your repo would see it. Where should it go?
Pick one answer.
Watch
A secret: A password, API key or token. Whoever has it can get in. waits, locked, in your repo settings. A workflow reads it by name, like ${{ secrets.MY_TOKEN }}. Printed by mistake? The log shows ***. Still, never print it.
Watch
Not every setting is secret. A site address is fine to show. Store it as a variable (configuration variable): A plain workflow setting that is not secret, like a site address., and read it as ${{ vars.SITE_URL }}. Sort these.
Drag a card into a box. Or tap the card, then tap the box.
Watch
An environment: A named place you deploy to, like production, with its own secrets and rules. is a named place you deploy to, like production. It can hold its own secrets. It can wait for a person to approve. Put a guarded deploy in order.
First step at the top. Put these in order. Use the arrows, or drag.
- The new site goes live
- The job gets the production secrets
- The deploy job starts, then waits
- A reviewer checks it and approves
Try it
Build the deploy workflow. Keys must come from secrets.
Tap blocks to add them. Put them in order.
Blocks
Your workflow
Tap a block above to start.
Workflow file .github/workflows/
name: Deploy
What runs
Nothing to run yet.
Hint
Trigger, then job, then steps. Build before you deploy.Predict
A stranger opens a PR from their fork. Your workflow runs on it. Does it get your secrets?
Pick one answer.
You did it!
You can now keep keys safe in your workflows.
Go deeper (optional)
Secrets live at three levels: organization, repository and environment. Environment secrets only reach jobs that use that environment. Environment rules can also limit deploys to main. On GitHub’s free plan, environments only work in public repos.
Bahasa Melayu
Deploy anda perlukan token Cloudflare. Tampal terus dalam ci.yml? Sesiapa yang boleh baca repo anda akan nampak. Di mana patut simpan?
Secret (rahsia) duduk berkunci dalam tetapan repo anda. Workflow baca ikut nama, contohnya ${{ secrets.MY_TOKEN }}. Tercetak tanpa sengaja? Log tunjuk ***. Namun, jangan sekali-kali cetak.
Bukan semua tetapan rahsia. Alamat laman boleh ditunjuk. Simpan sebagai variable (pemboleh ubah), dan baca sebagai ${{ vars.SITE_URL }}. Susun yang ini.
Environment (persekitaran) ialah tempat bernama untuk deploy, contohnya production. Ia boleh simpan rahsia sendiri. Ia boleh tunggu kelulusan seseorang. Susun deploy yang dikawal ini.
Bina workflow deploy. Kunci mesti datang dari secrets.
Orang asing buka PR dari fork mereka. Workflow anda berjalan padanya. Adakah ia dapat rahsia anda?
Kini anda boleh jaga kunci dengan selamat dalam workflow.
You finished this before. Practice is always welcome!
Official docs: Using secrets in GitHub Actions · Variables reference · Managing environments
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?