diff --git a/.github/workflows/environments-secrets.yml b/.github/workflows/environments-secrets.yml index 2b128265..91020f48 100644 --- a/.github/workflows/environments-secrets.yml +++ b/.github/workflows/environments-secrets.yml @@ -1,11 +1,11 @@ name: 03-1. Environments and Secrets on: - # push: - # branches: [main] - # pull_request: - # branches: [main] - workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: # Limit the permissions of the GITHUB_TOKEN permissions: @@ -19,6 +19,23 @@ env: DEV_URL: 'https://docs.github.com/en/developers' jobs: + use-secrets: + name: Use secrets + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + steps: + - name: Hello world action with secrets + uses: actions/hello-world-javascript-action@main + with: # Set the secret as an input + who-to-greet: ${{ secrets.MY_REPO_SECRET }} + env: # Or as an environment variable + super_secret: ${{ secrets.MY_REPO_SECRET }} + - name: Echo secret is redacted in the logs + run: | + echo Env secret is ${{ secrets.MY_REPO_SECRET }} + echo Warning: GitHub automatically redacts secrets printed to the log, + echo but you should avoid printing secrets to the log intentionally. + echo ${{ secrets.MY_REPO_SECRET }} | sed 's/./& /g' use-environment-dev: name: Use DEV environment runs-on: ubuntu-latest @@ -72,12 +89,28 @@ jobs: echo Org secret is ${{ secrets.MY_ORG_SECRET }} echo Env secret is not accessible ${{ secrets.MY_ENV_SECRET }} + use-environment-uat: + name: Use UAT environment + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + needs: use-environment-test + + environment: + name: UAT + url: 'https://uat.github.com' + + steps: + - name: Step that uses the UAT environment + run: echo "Deployment to UAT..." + env: + env_secret: ${{ secrets.MY_ENV_SECRET }} + use-environment-prod: name: Use PROD environment runs-on: ubuntu-latest #if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - needs: use-environment-test + needs: use-environment-uat environment: name: PROD diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index e8540e80..bf29a9ab 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -3,6 +3,12 @@ on: workflow_dispatch: workflow_call: + push: + branches: + - main + paths: + - 'labs/**' + jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest @@ -20,3 +26,12 @@ jobs: - run: echo "🍏 This job's status is ${{ job.status }}." - name: Adding markdown run: echo "### Hello world! :rocket:" >> "$GITHUB_STEP_SUMMARY" + + - name: Hello world + uses: actions/hello-world-javascript-action@main + with: + who-to-greet: "Mona the Octocat" + id: hello + # This step prints an output (time) from the previous step's action. + - name: Echo the greeting's time + run: echo 'The time was ${{ steps.hello.outputs.time }}.' diff --git a/.github/workflows/job-dependencies.yml b/.github/workflows/job-dependencies.yml index e773fe04..e9d3b239 100644 --- a/.github/workflows/job-dependencies.yml +++ b/.github/workflows/job-dependencies.yml @@ -2,9 +2,10 @@ name: 02-2. Dependencies on: workflow_dispatch: - # push: - # branches: - # - main + push: + branches: + - main + workflow_call: jobs: initial: @@ -31,3 +32,40 @@ jobs: needs: [fanout1, fanout2] steps: - run: echo "This job will run after fanout1 and fanout2 have finished." + build: + runs-on: ubuntu-latest + strategy: + matrix: + configuration: [debug, release] + steps: + - run: echo "This job builds the cofiguration ${{ matrix.configuration }}." + test: + runs-on: ubuntu-latest + needs: build + steps: + - run: echo "This job will be run after the build job." + ring01: + runs-on: ubuntu-latest + needs: test + steps: + - run: echo "This job will be run after the test job." + ring02: + runs-on: macos-latest + needs: test + steps: + - run: echo "This job will be run after the test job." + ring03: + runs-on: ubuntu-latest + needs: test + steps: + - run: echo "This job will be run after the test job." + ring04: + runs-on: ubuntu-latest + needs: [ring01,ring02,ring03] + steps: + - run: echo "This job will be run after the ring01,ring02,ring03 jobs." + prod: + runs-on: ubuntu-latest + needs: [ring04] + steps: + - run: echo "This job will be run after the ring04 job." diff --git a/.github/workflows/reusable-workflow-template.yml b/.github/workflows/reusable-workflow-template.yml index 33c7858e..b4698c5a 100644 --- a/.github/workflows/reusable-workflow-template.yml +++ b/.github/workflows/reusable-workflow-template.yml @@ -1,7 +1,9 @@ name: 04-1. Call Reusable Workflow Templates -on: - [workflow_dispatch] +on: + push: + branches: [main] + workflow_dispatch: jobs: call_greet_everyone_workflow_job: @@ -15,3 +17,6 @@ jobs: call_demo_workflow_job: needs: call_greet_everyone_workflow_job uses: githubabcs/gh-abcs-actions/.github/workflows/github-actions-demo.yml@main + call_dependencies_workflow_job: + needs: call_reusable_workflow_job + uses: tassosgomes/gh-abcs-actions/.github/workflows/job-dependencies.yml@main diff --git a/labs/lab01.md b/labs/lab01.md index 568071c9..9c2c82ee 100644 --- a/labs/lab01.md +++ b/labs/lab01.md @@ -6,7 +6,7 @@ References: - [Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows) - [Adding an action to your workflow](https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions#adding-an-action-to-your-workflow) -## 1.1 Update the workflow to trigger when a change is made to the labs folder on main branch +## 1.1 Update the workflow to trigger when a change is made to the labs folder on main branch (done) 1. Open the workflow file [github-actions-demo.yml](/.github/workflows/github-actions-demo.yml) 2. Edit the file and copy the following YAML content after line 4: @@ -22,7 +22,7 @@ References: 5. Commit the changes into the `main` branch 6. Go to `Actions` and see the details of your running workflow -## 1.2 Add steps to your workflow +## 1.2 Add steps to your workflow (done) 1. Open the workflow file [github-actions-demo.yml](/.github/workflows/github-actions-demo.yml) 2. Edit the file and copy the following YAML content at the end of the file: diff --git a/labs/lab02.md b/labs/lab02.md index 0b57698c..11df3622 100644 --- a/labs/lab02.md +++ b/labs/lab02.md @@ -7,7 +7,7 @@ References: - [Using jobs in a workflow](https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow) - [Environment variables](https://docs.github.com/en/actions/learn-github-actions/environment-variables) -## 2.1 Add new jobs with dependencies +## 2.1 Add new jobs with dependencies (done) 1. Open the workflow file [job-dependencies.yml](/.github/workflows/job-dependencies.yml) 2. Edit the file and copy the following YAML content at the end of the file: diff --git a/labs/lab03.md b/labs/lab03.md index 27c0755e..38007b3d 100644 --- a/labs/lab03.md +++ b/labs/lab03.md @@ -50,7 +50,7 @@ on: 8. Go to `Actions` and see the details of your running workflow -## 3.2 Add a new workflow job to deploy to UAT environment +## 3.2 Add a new workflow job to deploy to UAT environment (done) 1. Open the workflow file [environments-secrets.yml](/.github/workflows/environments-secrets.yml) 2. Edit the file and copy the following YAML content between the test and prod jobs (before the `use-environment-prod:` line): diff --git a/labs/setup.md b/labs/setup.md index 2cd443dc..7ee51fe3 100644 --- a/labs/setup.md +++ b/labs/setup.md @@ -8,7 +8,7 @@ References: ## Fork the current repository and enable GitHub Actions -1. Fork the current repository [gh-abcs-actions](https://github.com/githubabcs/gh-abcs-actions) +1. Fork the current repository [gh-abcs-actions](https://github.com/martins-vds/gh-abcs-actions) 2. Optional, copy or clone the repository by importing the repository into your account. 3. Go to `Actions` and see the warning message > Workflows aren’t being run on this forked repository @@ -29,4 +29,4 @@ References: - [ ] Module 6: Self-hosted runners - [ ] Module 7: CI/CD ``` -7. Fetch upstream to get the latest changes from the upstream repository \ No newline at end of file +7. Fetch upstream to get the latest changes from the upstream repository