diff --git a/.github/script/STEP b/.github/steps/-step.txt similarity index 100% rename from .github/script/STEP rename to .github/steps/-step.txt diff --git a/.github/steps/0-welcome.md b/.github/steps/0-welcome.md new file mode 100644 index 0000000..9ff13a5 --- /dev/null +++ b/.github/steps/0-welcome.md @@ -0,0 +1 @@ + diff --git a/.github/steps/1-configure-label-based-job.md b/.github/steps/1-configure-label-based-job.md new file mode 100644 index 0000000..32ca48f --- /dev/null +++ b/.github/steps/1-configure-label-based-job.md @@ -0,0 +1,52 @@ +## Step 1: Trigger a job based on labels + +_Welcome to the course :tada:_ + +![Screen Shot 2022-06-07 at 4 01 43 PM](https://user-images.githubusercontent.com/6351798/172490466-00f27580-8906-471f-ae83-ef3b6370df7d.png) + +A lot of things go into delivering "continuously". These things can range from culture and behavior to specific automation. In this exercise, we're going to focus on the deployment part of our automation. + +In a GitHub Actions workflow, the `on` step defines what causes the workflow to run. In this case, we want the workflow to run different tasks when specific labels are applied to a pull request. + +We'll use labels as triggers for multiple tasks: + +- When someone applies a "spin up environment" label to a pull request, that'll tell GitHub Actions that we'd like to set up our resources on an Azure environment. +- When someone applies a "stage" label to a pull request, that'll be our indicator that we'd like to deploy our application to a staging environment. +- When someone applies a "destroy environment" label to a pull request, we'll tear down any resources that are running on our Azure account. + +### :keyboard: Activity 1: Configure `GITHUB_TOKEN` permissions + +At the start of each workflow run, GitHub automatically creates a unique `GITHUB_TOKEN` secret to use in your workflow. We need to make sure this token has the permissions required for this course. + +1. Open a new browser tab, and work on the steps in your second tab while you read the instructions in this tab. +1. Go to Settings > Actions > General. Ensure that the `GITHUB_TOKEN` also has **Read and write permissions** enabled under **Workflow permissions**. This is required for your workflow to be able to upload your image to the container registry. + +### :keyboard: Activity 2: Configure a trigger based on labels + +For now, we'll focus on staging. We'll spin up and destroy our environment in a later step. + +1. Go to the **Actions** tab. +1. Click **New workflow** +1. Search for "simple workflow" and click **Configure** +1. Name your workflow `deploy-staging.yml` +1. Edit the contents of this file and remove all triggers and jobs. +1. Edit the contents of the file to add a conditional that filters the `build` job when there is a label present called **stage**. Your resulting file should look like this: + + ```yaml + name: Stage the app + + on: + pull_request: + types: [labeled] + + jobs: + build: + runs-on: ubuntu-latest + + if: contains(github.event.pull_request.labels.*.name, 'stage') + ``` + +1. Click **Start commit**, and choose to make a new branch named `staging-workflow`. +1. Click **Propose changes**. +1. Click **Create pull request**. +1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/2-setup-azure-environment.md b/.github/steps/2-setup-azure-environment.md new file mode 100644 index 0000000..9a04a65 --- /dev/null +++ b/.github/steps/2-setup-azure-environment.md @@ -0,0 +1,182 @@ +## Step 2: Set up an Azure environment + +_Good job getting started :gear:_ + +### Nice work triggering a job on specific labels + +We won't be going into detail on the steps of this workflow, but it would be a good idea to become familiar with the actions we're using. They are: + +- [`actions/checkout`](https://github.com/actions/checkout) +- [`actions/upload-artifact`](https://github.com/actions/upload-artifact) +- [`actions/download-artifact`](https://github.com/actions/download-artifact) +- [`docker/login-action`](https://github.com/docker/login-action) +- [`docker/build-push-action`](https://github.com/docker/build-push-action) +- [`azure/login`](https://github.com/Azure/login) +- [`azure/webapps-deploy`](https://github.com/Azure/webapps-deploy) + +### :keyboard: Activity 1: Store your credentials in GitHub secrets and finish setting up your workflow + +1. In a new tab, [create an Azure account](https://azure.microsoft.com/en-us/free/) if you don't already have one. If your Azure account is created through work, you may encounter issues accessing the necessary resources -- we recommend creating a new account for personal use and for this course. + > **Note**: You may need a credit card to create an Azure account. If you're a student, you may also be able to take advantage of the [Student Developer Pack](https://education.github.com/pack) for access to Azure. If you'd like to continue with the course without an Azure account, Skills will still respond, but none of the deployments will work. +1. Create a [new subscription](https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/create-subscription) in the Azure Portal. + > **Note**: your subscription must be configured "Pay as you go" which will require you to enter billing information. This course will only use a few minutes from your free plan, but Azure requires the billing information. +1. Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) on your machine. +1. In your terminal, run: + ```shell + az login + ``` +1. Copy the value of the `id:` field to a safe place. We'll call this `AZURE_SUBSCRIPTION_ID`. Here's an example of what it looks like: + ```shell + [ + { + "cloudName": "AzureCloud", + "id": "f****a09-****-4d1c-98**-f**********c", # <-- Copy this id field + "isDefault": true, + "name": "some-subscription-name", + "state": "Enabled", + "tenantId": "********-a**c-44**-**25-62*******61", + "user": { + "name": "mdavis******@*********.com", + "type": "user" + } + } + ] + ``` +1. In your terminal, run the command below. + + ````shell + az ad sp create-for-rbac --name "GitHub-Actions" --role contributor \ + --scopes /subscriptions/{subscription-id} \ + --sdk-auth + + # Replace {subscription-id} with the same id stored in AZURE_SUBSCRIPTION_ID. + ``` + + > **Note**: The `\` character works as a line break on Unix based systems. If you are on a Windows based system the `\` character will cause this command to fail. Place this command on a single line if you are using Windows.\*\* + + ```` + +1. Copy the entire contents of the command's response, we'll call this `AZURE_CREDENTIALS`. Here's an example of what it looks like: + ```shell + { + "clientId": "", + "clientSecret": "", + "subscriptionId": "", + "tenantId": "", + (...) + } + ``` +1. Back on GitHub, click on this repository's **Secrets and variables > Actions** in the Settings tab. +1. Click **New repository secret** +1. Name your new secret **AZURE_SUBSCRIPTION_ID** and paste the value from the `id:` field in the first command. +1. Click **Add secret**. +1. Click **New repository secret** again. +1. Name the second secret **AZURE_CREDENTIALS** and paste the entire contents from the second terminal command you entered. +1. Click **Add secret** +1. Go back to the Pull requests tab and in your pull request go to the **Files Changed** tab. Find and then edit the `.github/workflows/deploy-staging.yml` file to use some new actions. + +The full workflow file, should look like this: + +```yaml +name: Deploy to staging + +on: + pull_request: + types: [labeled] + +env: + IMAGE_REGISTRY_URL: ghcr.io + ############################################### + ### Replace with GitHub username ### + ############################################### + DOCKER_IMAGE_NAME: -azure-ttt + AZURE_WEBAPP_NAME: -ttt-app + ############################################### + +jobs: + build: + if: contains(github.event.pull_request.labels.*.name, 'stage') + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: npm install and build webpack + run: | + npm install + npm run build + - uses: actions/upload-artifact@v3 + with: + name: webpack artifacts + path: public/ + + Build-Docker-Image: + runs-on: ubuntu-latest + needs: build + name: Build image and store in GitHub Container Registry + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download built artifact + uses: actions/download-artifact@v3 + with: + name: webpack artifacts + path: public + + - name: Log in to GHCR + uses: docker/login-action@v2 + with: + registry: ${{ env.IMAGE_REGISTRY_URL }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{env.IMAGE_REGISTRY_URL}}/${{ github.repository }}/${{env.DOCKER_IMAGE_NAME}} + tags: | + type=sha,format=long,prefix= + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + Deploy-to-Azure: + runs-on: ubuntu-latest + needs: Build-Docker-Image + name: Deploy app container to Azure + steps: + - name: "Login via Azure CLI" + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/docker-login@v1 + with: + login-server: ${{env.IMAGE_REGISTRY_URL}} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy web app container + uses: azure/webapps-deploy@v2 + with: + app-name: ${{env.AZURE_WEBAPP_NAME}} + images: ${{env.IMAGE_REGISTRY_URL}}/${{ github.repository }}/${{env.DOCKER_IMAGE_NAME}}:${{ github.sha }} + + - name: Azure logout via Azure CLI + uses: azure/CLI@v1 + with: + inlineScript: | + az logout + az cache purge + az account clear +``` + +16. After you've edited the file, click **Commit changes...** and commit to the `staging-workflow` branch. +17. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/3-spinup-environment.md b/.github/steps/3-spinup-environment.md new file mode 100644 index 0000000..6519d5a --- /dev/null +++ b/.github/steps/3-spinup-environment.md @@ -0,0 +1,142 @@ +## Step 3: Spin up an environment based on labels + +_Nicely done! :heart:_ + +GitHub Actions is cloud agnostic, so any cloud will work. We'll show how to deploy to Azure in this course. + +**What are _Azure resources_?** In Azure, a resource is an entity managed by Azure. We'll use the following Azure resources in this course: + +- A [web app](https://docs.microsoft.com/en-us/azure/app-service/overview) is how we'll be deploying our application to Azure. +- A [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview#resource-groups) is a collection of resources, like web apps and virtual machines (VMs). +- An [App Service plan](https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans) is what runs our web app and manages the billing (our app should run for free). + +Through the power of GitHub Actions, we can create, configure, and destroy these resources through our workflow files. + +### :keyboard: Activity 1: Set up a personal access token (PAT) + +Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub. We will use a PAT to allow your web app to pull the container image after your workflow pushes a newly built image to the registry. + +1. Open a new browser tab, and work on the steps in your second tab while you read the instructions in this tab. +2. Create a personal access token with the `repo` and `read:packages` scopes. For more information, see ["Creating a personal access token."](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) +3. Once you have generated the token we will need to store it in a secret so that it can be used within a workflow. Create a new repository secret named `CR_PAT` and paste the PAT token in as the value. +4. With this done we can move on to setting up our workflow. + +**Configuring your Azure environment** + +To deploy successfully to our Azure environment: + +1. Create a new branch called `azure-configuration` by clicking on the branch dropdown on the top, left hand corner of the `Code` tab on your repository page. +2. Once you're in the new `azure-configuration` branch, go into the `.github/workflows` directory and create a new file titled `spinup-destroy.yml` by clicking **Add file**. + +Copy and paste the following into this new file: + +```yaml +name: Configure Azure environment + +on: + pull_request: + types: [labeled] + +env: + IMAGE_REGISTRY_URL: ghcr.io + AZURE_RESOURCE_GROUP: cd-with-actions + AZURE_APP_PLAN: actions-ttt-deployment + AZURE_LOCATION: '"Central US"' + ############################################### + ### Replace with GitHub username ### + ############################################### + AZURE_WEBAPP_NAME: -ttt-app + +jobs: + setup-up-azure-resources: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'spin up environment') + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Azure login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Create Azure resource group + if: success() + run: | + az group create --location ${{env.AZURE_LOCATION}} --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} + + - name: Create Azure app service plan + if: success() + run: | + az appservice plan create --resource-group ${{env.AZURE_RESOURCE_GROUP}} --name ${{env.AZURE_APP_PLAN}} --is-linux --sku F1 --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} + + - name: Create webapp resource + if: success() + run: | + az webapp create --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --plan ${{ env.AZURE_APP_PLAN }} --name ${{ env.AZURE_WEBAPP_NAME }} --deployment-container-image-name nginx --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} + + - name: Configure webapp to use GHCR + if: success() + run: | + az webapp config container set --docker-custom-image-name nginx --docker-registry-server-password ${{secrets.CR_PAT}} --docker-registry-server-url https://${{env.IMAGE_REGISTRY_URL}} --docker-registry-server-user ${{github.actor}} --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} + + destroy-azure-resources: + runs-on: ubuntu-latest + + if: contains(github.event.pull_request.labels.*.name, 'destroy environment') + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Azure login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Destroy Azure environment + if: success() + run: | + az group delete --name ${{env.AZURE_RESOURCE_GROUP}} --subscription ${{secrets.AZURE_SUBSCRIPTION_ID}} --yes +``` + +3. Click **Commit changes...** and select `Commit directly to the azure-configuration branch.` before clicking **Commit changes**. +4. Go to the Pull requests tab of the repository. +5. There should be a yellow banner with the `azure-configuration` branch where you can click **Compare & pull request**. +6. Set the title of the Pull request to: `Added spinup-destroy.yml workflow` and click `Create pull request`. + +We will cover the key functionality below and then put the workflow to use by applying a label to the pull request. + +This new workflow has two jobs: + +1. **Set up Azure resources** will run if the pull request contains a label with the name "spin up environment". +2. **Destroy Azure resources** will run if the pull request contains a label with the name "destroy environment". + +In addition to each job, there's a few global environment variables: + +- `AZURE_RESOURCE_GROUP`, `AZURE_APP_PLAN`, and `AZURE_WEBAPP_NAME` are names for our resource group, app service plan, and web app, respectively, which we'll reference over multiple steps and workflows +- `AZURE_LOCATION` lets us specify the [region](https://azure.microsoft.com/en-us/global-infrastructure/regions/) for the data centers, where our app will ultimately be deployed. + +**Setting up Azure resources** + +The first job sets up the Azure resources as follows: + +1. Logs into your Azure account with the [`azure/login`](https://github.com/Azure/login) action. The `AZURE_CREDENTIALS` secret you created earlier is used for authentication. +1. Creates an [Azure resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview#resource-groups) by running [`az group create`](https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-create) on the Azure CLI, which is [pre-installed on the GitHub-hosted runner](https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners). +1. Creates an [App Service plan](https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans) by running [`az appservice plan create`](https://docs.microsoft.com/en-us/cli/azure/appservice/plan?view=azure-cli-latest#az-appservice-plan-create) on the Azure CLI. +1. Creates a [web app](https://docs.microsoft.com/en-us/azure/app-service/overview) by running [`az webapp create`](https://docs.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-create) on the Azure CLI. +1. Configures the newly created web app to use [GitHub Packages](https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages) by using [`az webapp config`](https://docs.microsoft.com/en-us/cli/azure/webapp/config?view=azure-cli-latest) on the Azure CLI. Azure can be configured to use its own [Azure Container Registry](https://docs.microsoft.com/en-us/azure/container-registry/), [DockerHub](https://docs.docker.com/docker-hub/), or a custom (private) registry. In this case, we'll configure GitHub Packages as a custom registry. + +**Destroying Azure resources** + +The second job destroys Azure resources so that you do not use your free minutes or incur billing. The job works as follows: + +1. Logs into your Azure account with the [`azure/login`](https://github.com/Azure/login) action. The `AZURE_CREDENTIALS` secret you created earlier is used for authentication. +1. Deletes the resource group we created earlier using [`az group delete`](https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-delete) on the Azure CLI. + +### :keyboard: Activity 2: Apply labels to create resources + +1. Edit the `spinup-destroy.yml` file in your open pull request and replace any `` placeholders with your GitHub username. Commit this change directly to the `azure-configuration` branch. +1. Back in the Pull request, create and apply the `spin up environment` label to your open pull request +1. Wait for the GitHub Actions workflow to run and spin up your Azure environment. You can follow along in the Actions tab or in the pull request merge box. +1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/4-deploy-to-staging-environment.md b/.github/steps/4-deploy-to-staging-environment.md new file mode 100644 index 0000000..be9f7ac --- /dev/null +++ b/.github/steps/4-deploy-to-staging-environment.md @@ -0,0 +1,17 @@ +## Step 4: Deploy to a staging environment based on labels + +_Nicely done, you used a workflow to spin up your Azure environment :dancer:_ + +Now that the proper configuration and workflow files are present, let's test our actions! In this step, there's a small change to the game. Once you add the appropriate label to your pull request, you should be able to see the deployment! + +1. Create a new branch named `staging-test` from `main` using the same steps as you did for the previous `azure-configuration` branch. +1. Edit the `.github/workflows/deploy-staging.yml` file, and replace every `` with your GitHub username. +1. Commit that change to the new `staging-test` branch. +1. Go to the Pull requests tab and there should be a yellow banner with the `staging-test` branch to `Compare & pull request`. Once the pull request is opened up, click `Create pull request`. + +### :keyboard: Activity 1: Add the proper label to your pull request + +1. Ensure that the `GITHUB_TOKEN` for this repository has read and write permissions under **Workflow permissions**. [Learn more](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token). This is required for your workflow to be able to upload your image to the container registry. +1. Create and apply the `stage` label to your open pull request +1. Wait for the GitHub Actions workflow to run and deploy the application to your Azure environment. You can follow along in the Actions tab or in the pull request merge box. The deployment may take a few moments but you've done the right thing. Once the deployment is successful, you'll see green check marks for each run, and you'll see a URL for your deployment. Play the game! +1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/5-deploy-to-prod-environment.md b/.github/steps/5-deploy-to-prod-environment.md new file mode 100644 index 0000000..bc2b94d --- /dev/null +++ b/.github/steps/5-deploy-to-prod-environment.md @@ -0,0 +1,128 @@ +## Step 5: Deploy to a production environment based on labels + +_Deployed! :ship:_ + +### Nicely done + +As we've done before, create a new branch called `production-deployment-workflow` from `main`. In the `.github/workflows` directory, add a new file titled `deploy-prod.yml`. This new workflow deals specifically with commits to `main` and handles deployments to `prod`. + +**Continuous delivery** (CD) is a concept that contains many behaviors and other, more specific concepts. One of those concepts is **test in production**. That can mean different things to different projects and different companies, and isn't a strict rule that says you are or aren't "doing CD". + +In our case, we can match our production environment to be exactly like our staging environment. This minimizes opportunities for surprises once we deploy to production. + +### :keyboard: Activity 1: Add triggers to production deployment workflow + +Copy and paste the following to your file, and replace any `` placeholders with your GitHub username. Note that not much has changed from our staging workflow, except for our trigger, and that we won't be filtering by labels. + +```yaml +name: Deploy to production + +on: + push: + branches: + - main + +env: + IMAGE_REGISTRY_URL: ghcr.io + ############################################### + ### Replace with GitHub username ### + ############################################### + DOCKER_IMAGE_NAME: -azure-ttt + AZURE_WEBAPP_NAME: -ttt-app + ############################################### + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: npm install and build webpack + run: | + npm install + npm run build + - uses: actions/upload-artifact@v3 + with: + name: webpack artifacts + path: public/ + + Build-Docker-Image: + runs-on: ubuntu-latest + needs: build + name: Build image and store in GitHub Container Registry + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download built artifact + uses: actions/download-artifact@v3 + with: + name: webpack artifacts + path: public + + - name: Log in to GHCR + uses: docker/login-action@v2 + with: + registry: ${{ env.IMAGE_REGISTRY_URL }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{env.IMAGE_REGISTRY_URL}}/${{ github.repository }}/${{env.DOCKER_IMAGE_NAME}} + tags: | + type=sha,format=long,prefix= + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + Deploy-to-Azure: + runs-on: ubuntu-latest + needs: Build-Docker-Image + name: Deploy app container to Azure + steps: + - name: "Login via Azure CLI" + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/docker-login@v1 + with: + login-server: ${{env.IMAGE_REGISTRY_URL}} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy web app container + uses: azure/webapps-deploy@v2 + with: + app-name: ${{env.AZURE_WEBAPP_NAME}} + images: ${{env.IMAGE_REGISTRY_URL}}/${{ github.repository }}/${{env.DOCKER_IMAGE_NAME}}:${{github.sha}} + + - name: Azure logout via Azure CLI + uses: azure/CLI@v1 + with: + inlineScript: | + az logout + az cache purge + az account clear +``` + +1. Update every `` to your GitHub username. +1. Commit your changes to the `production-deployment-workflow` branch. +1. Go to the Pull requests tab and click **Compare & pull request** for the `production-deployment-workflow` branch and create a Pull request. + +Great! The syntax you used tells GitHub Actions to only run that workflow when a commit is made to the main branch. Now we can put this workflow into action to deploy to production! + +### :keyboard: Activity 2: Merge your pull request + +1. You can now [merge](https://docs.github.com/en/get-started/quickstart/github-glossary#merge) your pull request! +1. Click **Merge pull request** and leave this tab open as we will be applying a label to the closed pull request in the next step. +1. Now we just have to wait for the package to be published to GitHub Container Registry and the deployment to occur. +1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/6-destroy-azure-environment.md b/.github/steps/6-destroy-azure-environment.md new file mode 100644 index 0000000..5b7f7f3 --- /dev/null +++ b/.github/steps/6-destroy-azure-environment.md @@ -0,0 +1,17 @@ +## Step 6: Production deployment + +_Nice work! :sparkle:_ + +Great work, you've done it! You should be able to see your container image in the **Packages** section of your account on the main repository page. You can get the deployment URL in the Actions log, just like the staging URL. + +### The cloud environment + +Throughout the course you've spun up resources that, if left unattended, could incur billing or consume your free minutes from the cloud provider. Once you have verified your application in production, let's tear down those environments so that you can keep your minutes for more learning! + +### :keyboard: Activity 1: Destroy any running resources so you don't incur charges + +1. Create and apply the `destroy environment` label to your merged `production-deployment-workflow` pull request. If you have already closed the tab with your pull request, you can open it again by clicking **Pull requests** and then clicking the **Closed** filter to view merged pull requests. + +Now that you've applied the proper label, let's wait for the GitHub Actions workflow to complete. When it's finished, you can confirm that your environment has been destroyed by visiting your app's URL, or by logging into the Azure portal to see it is not running. + +2. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step. diff --git a/.github/steps/X-finish.md b/.github/steps/X-finish.md new file mode 100644 index 0000000..ffbbf51 --- /dev/null +++ b/.github/steps/X-finish.md @@ -0,0 +1,26 @@ + + +## Finish + +celebrate + +### Congratulations, you've completed this course! + +Here's a recap of all the tasks you've accomplished in your repository: + +- Trigger a job based on labels +- Set up the Azure environment +- Spin up environment based on labels +- Deploy to a staging environment based on labels +- Deploy to a production environment based on labels +- Destroy environment based on labels + +### What's next? + +- [We'd love to hear what you thought of this course](https://github.com/skills/.github/discussions). +- [Take another GitHub Skills Course](https://github.com/skills). +- [Read the GitHub Getting Started docs](https://docs.github.com/en/get-started). +- To find projects to contribute to, check out [GitHub Explore](https://github.com/explore). diff --git a/.github/workflows/0-start.yml b/.github/workflows/0-welcome.yml similarity index 59% rename from .github/workflows/0-start.yml rename to .github/workflows/0-welcome.yml index 689988f..77c86de 100644 --- a/.github/workflows/0-start.yml +++ b/.github/workflows/0-welcome.yml @@ -1,26 +1,24 @@ -name: Step 0, Start +name: Step 0, Welcome # This step triggers after the learner creates a new repository from the template -# This step sets STEP to 1 -# This step closes
and opens
+# This workflow updates from step 0 to step 1. -# When creating a repository from a template, there is variability in the -# order and timing of events that fire and when workflow triggers are registered. +# When creating a repository from a template, there is variability in the +# order and timing of events that fire and when workflow triggers are registered. # Given that, these triggers are purposely broad to ensure this workflow is always triggered. # The conditions within the on_start job are to ensure it is only fully executed once. -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: create: workflow_dispatch: - + permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -29,7 +27,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -38,35 +36,34 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 0 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 0. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 0 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Update README to comment out step0 and open
- # and set STEP to '1' + # Update README from step 0 to step 1. - name: Update to step 1 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 0 to_step: 1 # This is required to establish a related history for branches - # after being created from the template repository + # after being created from the template repository. - name: Initialize repository run: ./.github/script/initialize-repository.sh --dry-run=false env: diff --git a/.github/workflows/1-configure-label-based-job.yml b/.github/workflows/1-configure-label-based-job.yml index 12fc440..912c14a 100644 --- a/.github/workflows/1-configure-label-based-job.yml +++ b/.github/workflows/1-configure-label-based-job.yml @@ -1,11 +1,10 @@ name: Step 1, Trigger a job based on labels -# This step triggers after 0-start.yml -# This step sets STEP to 2 -# This step closes
and opens
+# This step triggers after 0-start.yml. +# This workflow updates from step 1 to step 2. -# This will run every time we push to the deploy-staging.yml file on the staging-workflow branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# This will run every time we push to the deploy-staging.yml file on the staging-workflow branch. +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: workflow_dispatch: push: @@ -15,13 +14,12 @@ on: - .github/workflows/deploy-staging.yml permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -30,7 +28,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -39,35 +37,34 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 1 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 1. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 1 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Verify the learner added the specific label triggers + # Verify the learner added the specific label triggers. - name: Verify workflow run: ./.github/script/check-file.sh env: FILE: .github/workflows/deploy-staging.yml SEARCH: "github.event.pull_request.labels\\.\\*.name.*stage" - # Update README to close
and open
- # and set STEP to '2' + # In README.md, switch step 1 for step 2. - name: Update to step 2 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 1 diff --git a/.github/workflows/2-setup-azure-environment.yml b/.github/workflows/2-setup-azure-environment.yml index 2b5b698..b78f962 100644 --- a/.github/workflows/2-setup-azure-environment.yml +++ b/.github/workflows/2-setup-azure-environment.yml @@ -1,10 +1,9 @@ name: Step 2, Set up the Azure environment -# This step sets STEP to 3 -# This step closes
and opens
+# This workflow updates from step 2 to step 3. # This will run every time we push to the deploy-staging.yml file on the staging-workflow branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: workflow_dispatch: push: @@ -14,14 +13,13 @@ on: - .github/workflows/deploy-staging.yml permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write pull-requests: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -30,7 +28,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -39,54 +37,53 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 2 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 2. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 2 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Verify the learner configured Build-Docker-Image job + # Verify the learner configured Build-Docker-Image job. - name: Verify Build-Docker-Image job run: .github/script/check-file.sh env: FILE: .github/workflows/deploy-staging.yml - SEARCH_LIST: 'Build-Docker-Image actions/download-artifact docker/login-action docker/build-push-action' + SEARCH_LIST: "Build-Docker-Image actions/download-artifact docker/login-action docker/build-push-action" - # Verify the learner configured the Deploy-to-Azure job + # Verify the learner configured the Deploy-to-Azure job. - name: Verify Deploy-to-Azure job run: .github/script/check-file.sh env: FILE: .github/workflows/deploy-staging.yml - SEARCH_LIST: 'Deploy-to-Azure azure/login azure/webapps-deploy' + SEARCH_LIST: "Deploy-to-Azure azure/login azure/webapps-deploy" - # Merge the pull open pull request + # Merge the pull open pull request. - name: Merge Pull Request run: gh pr merge --squash staging-workflow env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Pull main + # Pull main. - name: Pull main run: ./.github/script/pull-main.sh env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Update README to close
and open
- # and set STEP to '3' + # In README.md, switch step 2 for step 3. - name: Update to step 3 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 2 diff --git a/.github/workflows/3-spinup-environment.yml b/.github/workflows/3-spinup-environment.yml index ac9a1bc..e9d35cd 100644 --- a/.github/workflows/3-spinup-environment.yml +++ b/.github/workflows/3-spinup-environment.yml @@ -1,11 +1,10 @@ name: Step 3, Spin up environment -# This step sets STEP to 4 -# This step closes
and opens
+# This workflow updates from step 3 to step 4. # This will run after the "Configure Azure environment" workflow -# completes on the azure-configuration branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# completes on the azure-configuration branch. +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: workflow_dispatch: workflow_run: @@ -14,14 +13,13 @@ on: branches: [azure-configuration] permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write pull-requests: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -30,7 +28,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -39,40 +37,39 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 3 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 3. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 3 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Merge the pull open pull request + # Merge the pull open pull request. - name: Merge Pull Request run: gh pr merge --squash azure-configuration env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Pull main + + # Pull main. - name: Pull main run: ./.github/script/pull-main.sh env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Update README to close
and open
- # and set STEP to '4' + # In README.md, switch step 3 for step 4. - name: Update to step 4 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 3 diff --git a/.github/workflows/4-deploy-to-staging-environment.yml b/.github/workflows/4-deploy-to-staging-environment.yml index bb4581a..12126bd 100644 --- a/.github/workflows/4-deploy-to-staging-environment.yml +++ b/.github/workflows/4-deploy-to-staging-environment.yml @@ -1,11 +1,10 @@ name: Step 4, Deploy to staging -# This step sets STEP to 5 -# This step closes
and opens
+# This workflow updates from step 4 to step 5. # This will run after the "Configure Azure environment" workflow # completes on the azure-configuration branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: workflow_dispatch: workflow_run: @@ -14,14 +13,13 @@ on: branches: [staging-test] permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata - contents: write + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. + contents: write pull-requests: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -30,7 +28,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -40,20 +38,20 @@ jobs: runs-on: ubuntu-latest # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 4 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 4. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 4 }} steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. # Merge the pull open pull request - name: Merge Pull Request @@ -61,16 +59,15 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Pull main + # Pull main. - name: Pull main run: ./.github/script/pull-main.sh env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Update README to close
and open
- # and set STEP to '5' + # In README.md, switch step 4 for step 5. - name: Update to step 5 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 4 diff --git a/.github/workflows/5-deploy-to-prod-environment.yml b/.github/workflows/5-deploy-to-prod-environment.yml index ee5b1d9..25fa3ab 100644 --- a/.github/workflows/5-deploy-to-prod-environment.yml +++ b/.github/workflows/5-deploy-to-prod-environment.yml @@ -1,11 +1,10 @@ name: Step 5, Test the deploy to staging workflow -# This step triggers after a pull requst is merged to `main` -# This step sets STEP to 6 +# This step triggers after a pull requst is merged to `main`. # This will run after the "Deploy to production"" workflow # completes on the production-deployment-workflow branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: workflow_dispatch: workflow_run: @@ -14,13 +13,12 @@ on: branches: [main] permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -29,7 +27,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -38,28 +36,27 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 5 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 5. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 5 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Update README to close
and open
- # and set STEP to '6' + # In README.md, switch step 5 for step 6. - name: Update to step 6 - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 5 diff --git a/.github/workflows/6-destroy-azure-environment.yml b/.github/workflows/6-destroy-azure-environment.yml index b525506..34b656b 100644 --- a/.github/workflows/6-destroy-azure-environment.yml +++ b/.github/workflows/6-destroy-azure-environment.yml @@ -1,12 +1,11 @@ name: Step 6, Production deployment cleanup -# This step sets STEP to X -# This step closes
and opens
+# This workflow updates from step 6 to step X. # This will run after the "Configure Azure environment" workflow # completes on the production-deployment-workflow branch -# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows -on: +# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows +on: workflow_dispatch: workflow_run: workflows: ["Configure Azure environment"] @@ -14,13 +13,12 @@ on: branches: [production-deployment-workflow] permissions: - # Need `contents: read` to checkout the repository - # Need `contents: write` to update the step metadata + # Need `contents: read` to checkout the repository. + # Need `contents: write` to update the step metadata. contents: write jobs: - # Get the current step from .github/script/STEP so we can - # limit running the main job when the learner is on the same step. + # Get the current step to only run the main job when the learner is on the same step. get_current_step: name: Check current step number runs-on: ubuntu-latest @@ -29,7 +27,7 @@ jobs: uses: actions/checkout@v3 - id: get_step run: | - echo "current_step=$(cat ./.github/script/STEP)" >> $GITHUB_OUTPUT + echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT outputs: current_step: ${{ steps.get_step.outputs.current_step }} @@ -38,28 +36,27 @@ jobs: needs: get_current_step # We will only run this action when: - # 1. This repository isn't the template repository - # 2. The STEP is currently 6 - # Reference https://docs.github.com/en/actions/learn-github-actions/contexts - # Reference https://docs.github.com/en/actions/learn-github-actions/expressions + # 1. This repository isn't the template repository. + # 2. The step is currently 6. + # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts + # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions if: >- ${{ !github.event.repository.is_template && needs.get_current_step.outputs.current_step == 6 }} - # We'll run Ubuntu for performance instead of Mac or Windows + # We'll run Ubuntu for performance instead of Mac or Windows. runs-on: ubuntu-latest steps: - # We'll need to check out the repository so that we can edit the README + # We'll need to check out the repository so that we can edit the README. - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 # Let's get all the branches + fetch-depth: 0 # Let's get all the branches. - # Update README to close
and open
- # and set STEP to 'X' + # In README.md, switch step 6 for step X. - name: Update to step X - uses: skills/action-update-step@v1 + uses: skills/action-update-step@v2 with: token: ${{ secrets.GITHUB_TOKEN }} from_step: 6 diff --git a/README.md b/README.md index 9ca3885..1ddfcd2 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ +
+ # Deploy to Azure _Create two deployment workflows using GitHub Actions and Microsoft Azure._ +
+ -
-

Welcome

+## Welcome Create two deployment workflows using GitHub Actions and Microsoft Azure. @@ -27,9 +27,18 @@ Create two deployment workflows using GitHub Actions and Microsoft Azure. - **What you'll learn**: We'll learn how to create a workflow that enables Continuous Delivery using GitHub Actions and Microsoft Azure. - **What you'll build**: We will create two deployment workflows - the first workflow to deploy to staging based on a label and the second workflow to deploy to production based on merging to main. - **Prerequisites**: Before you start, you should be familiar with GitHub, GitHub Actions, and Continuous Integration with GitHub Actions. -- **How long**: This course is 6 steps long and takes less than 2 hours to complete. +- **How long**: This course takes less than 2 hours to complete. + +In this course, you will: -## How to start this course +1. Configure a job +2. Set up an Azure environment +3. Spin up the environment +4. Deploy to staging +5. Deploy to production +6. Destroy the environment + +### How to start this course - -
-

Finish

- -celebrate - -### Congratulations, you've completed this course! - -Here's a recap of all the tasks you've accomplished in your repository: - -- Trigger a job based on labels -- Set up the Azure environment -- Spin up environment based on labels -- Deploy to a staging environment based on labels -- Deploy to a production environment based on labels -- Destroy environment based on labels - -### What's next? - -- [We'd love to hear what you thought of this course](https://github.com/skills/.github/discussions). -- [Take another GitHub Skills Course](https://github.com/skills). -- [Read the GitHub Getting Started docs](https://docs.github.com/en/get-started). -- To find projects to contribute to, check out [GitHub Explore](https://github.com/explore). - -
+
--- + Get help: [Post in our discussion board](https://github.com/skills/.github/discussions) • [Review the GitHub status page](https://www.githubstatus.com/) -© 2022 GitHub • [Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md) • [MIT License](https://gh.io/mit) +© 2023 GitHub • [Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md) • [MIT License](https://gh.io/mit) + +
diff --git a/__test__/game.test.js b/__test__/game.test.js index e8aa3a8..9e48105 100644 --- a/__test__/game.test.js +++ b/__test__/game.test.js @@ -1,108 +1,108 @@ -const Game = require('../src/game').default -const fs = require('fs') +const Game = require("../src/game").default; +const fs = require("fs"); -describe('App', () => { - it('Contains the compiled JavaScript', async (done) => { - fs.readFile('./public/main.js', 'utf8', (err, data) => { - expect(err).toBe(null) - expect(data).toMatchSnapshot() - done() - }) - }) -}) +describe("App", () => { + it("Contains the compiled JavaScript", async (done) => { + fs.readFile("./public/main.js", "utf8", (err, data) => { + expect(err).toBe(null); + expect(data).toMatchSnapshot(); + done(); + }); + }); +}); -describe('Game', () => { - let game, p1, p2 +describe("Game", () => { + let game, p1, p2; beforeEach(() => { - p1 = 'Salem' - p2 = 'Nate' - game = new Game(p1, p2) - }) + p1 = "Salem"; + p2 = "Nate"; + game = new Game(p1, p2); + }); - describe('Game', () => { - it('Initializes with two players', async () => { - expect(game.p1).toBe('Salem') - expect(game.p2).toBe('Nate') - }) + describe("Game", () => { + it("Initializes with two players", async () => { + expect(game.p1).toBe("Salem"); + expect(game.p2).toBe("Nate"); + }); - it('Initializes with an empty board', async () => { + it("Initializes with an empty board", async () => { for (let r = 0; r < game.board.length; r++) { for (let c = 0; c < game.board[r].lenght; c++) { - expect(game.board[r][c]).toBeUndefined() + expect(game.board[r][c]).toBeUndefined(); } } - }) + }); - it('Starts the game with a random player', async () => { - Math.random = () => 0.4 - expect(new Game(p1, p2).player).toBe('Salem') + it("Starts the game with a random player", async () => { + Math.random = () => 0.4; + expect(new Game(p1, p2).player).toBe("Salem"); - Math.random = () => 0.6 - expect(new Game(p1, p2).player).toBe('Nate') - }) - }) + Math.random = () => 0.6; + expect(new Game(p1, p2).player).toBe("Nate"); + }); + }); - describe('turn', () => { + describe("turn", () => { it("Inserts an 'X' into the top center", async () => { - game.turn(0, 1) - expect(game.board[0][1]).toBe('X') - }) + game.turn(0, 1); + expect(game.board[0][1]).toBe("X"); + }); it("Inserts an 'X' into the top left", async () => { - game.turn(0) - expect(game.board[0][0]).toBe('X') - }) - }) + game.turn(0); + expect(game.board[0][0]).toBe("X"); + }); + }); - describe('nextPlayer', () => { - it('Sets the current player to be whoever it is not', async () => { - Math.random = () => 0.4 - const game = new Game(p1, p2) - expect(game.player).toBe('Salem') - game.nextPlayer() - expect(game.player).toBe('Nate') - }) - }) + describe("nextPlayer", () => { + it("Sets the current player to be whoever it is not", async () => { + Math.random = () => 0.4; + const game = new Game(p1, p2); + expect(game.player).toBe("Salem"); + game.nextPlayer(); + expect(game.player).toBe("Nate"); + }); + }); - describe('hasWinner', () => { - it('Wins if any row is filled', async () => { + describe("hasWinner", () => { + it("Wins if any row is filled", async () => { for (let r = 0; r < game.board.length; r++) { for (let c = 0; c < game.board[r].length; c++) { - game.board[r][c] = 'X' + game.board[r][c] = "X"; } - expect(game.hasWinner()).toBe(true) + expect(game.hasWinner()).toBe(true); for (let c = 0; c < game.board[r].length; c++) { - game.board[r][c] = null + game.board[r][c] = null; } } - }) + }); - it('Wins if any column is filled', async () => { + it("Wins if any column is filled", async () => { for (let r = 0; r < game.board.length; r++) { for (let c = 0; c < game.board[r].length; c++) { - game.board[c][r] = 'X' + game.board[c][r] = "X"; } - expect(game.hasWinner()).toBe(true) + expect(game.hasWinner()).toBe(true); for (let c = 0; c < game.board[r].length; c++) { - game.board[c][r] = null + game.board[c][r] = null; } } - }) + }); - it('Wins if down-left diagonal is filled', async () => { + it("Wins if down-left diagonal is filled", async () => { for (let r = 0; r < game.board.length; r++) { - game.board[r][r] = 'X' + game.board[r][r] = "X"; } - expect(game.hasWinner()).toBe(true) - }) + expect(game.hasWinner()).toBe(true); + }); - it('Wins if up-right diagonal is filled', async () => { + it("Wins if up-right diagonal is filled", async () => { for (let r = 0; r < game.board.length; r++) { - game.board[2 - r][r] = 'X' + game.board[2 - r][r] = "X"; } - expect(game.hasWinner()).toBe(true) - }) - }) -}) + expect(game.hasWinner()).toBe(true); + }); + }); +}); diff --git a/babel.config.js b/babel.config.js index c76a0d0..392abb6 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,12 +1,12 @@ module.exports = { presets: [ [ - '@babel/preset-env', + "@babel/preset-env", { targets: { - node: 'current' - } - } - ] - ] -} + node: "current", + }, + }, + ], + ], +}; diff --git a/handler.js b/handler.js index d1ac2c1..03b04da 100644 --- a/handler.js +++ b/handler.js @@ -1,20 +1,23 @@ -const fs = require('fs') -const path = require('path') +const fs = require("fs"); +const path = require("path"); const files = { - '/public/index.css': { - content: fs.readFileSync(path.join(__dirname, 'public', 'index.css'), 'utf8'), - type: 'text/css' + "/public/index.css": { + content: fs.readFileSync( + path.join(__dirname, "public", "index.css"), + "utf8" + ), + type: "text/css", }, - '/public/main.js': { - content: fs.readFileSync(path.join(__dirname, 'public', 'main.js'), 'utf8'), - type: 'text/javascript' + "/public/main.js": { + content: fs.readFileSync(path.join(__dirname, "public", "main.js"), "utf8"), + type: "text/javascript", }, - '/': { - content: fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8'), - type: 'text/html' - } -} + "/": { + content: fs.readFileSync(path.join(__dirname, "index.html"), "utf8"), + type: "text/html", + }, +}; /** * @@ -30,12 +33,12 @@ const files = { */ exports.lambdaHandler = async (event, context) => { // This will either be /, /public/index.css, or /public/main.js - const requestPath = event.path - const { content, type } = files[requestPath] + const requestPath = event.path; + const { content, type } = files[requestPath]; return { - headers: { 'content-type': type }, + headers: { "content-type": type }, statusCode: 200, - body: content - } -} + body: content, + }; +}; diff --git a/index.html b/index.html index 8fcb10d..7ace763 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,9 @@ - - - + + + TicTacToe @@ -20,7 +20,7 @@

- + diff --git a/package.json b/package.json index 941eed8..7f9c194 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "kind-of": "^6.0.3", "node-forge": "^1.3.0" }, - "jest" : { + "jest": { "testRunner": "jest-jasmine2" } } diff --git a/public/index.css b/public/index.css index a272fc2..b1040cb 100644 --- a/public/index.css +++ b/public/index.css @@ -1,4 +1,6 @@ -#game { display: flex; } +#game { + display: flex; +} #tictactoe { border-collapse: collapse; @@ -16,7 +18,7 @@ } #tictactoe td:hover { - background: #CCCCCC; + background: #cccccc; } #tictactoe tr { @@ -41,8 +43,9 @@ border-bottom: thin solid black; } -#score h2 { margin-top: 0; } - +#score h2 { + margin-top: 0; +} #app { margin: auto; diff --git a/src/game.js b/src/game.js index a30a0fa..2832d03 100644 --- a/src/game.js +++ b/src/game.js @@ -1,51 +1,61 @@ export default class Game { - constructor (p1, p2) { - this.p1 = p1 - this.p2 = p2 - this.board = [[null, null, null], [null, null, null], [null, null, null]] - this.player = Math.random() < 0.5 ? this.p1 : this.p2 - this.sym = 'X' + constructor(p1, p2) { + this.p1 = p1; + this.p2 = p2; + this.board = [ + [null, null, null], + [null, null, null], + [null, null, null], + ]; + this.player = Math.random() < 0.5 ? this.p1 : this.p2; + this.sym = "X"; } - turn (row, col) { - col = col || row - this.board[row][col] = this.sym + turn(row, col) { + col = col || row; + this.board[row][col] = this.sym; } - nextPlayer () { - this.player = this.player === this.p1 ? this.p2 : this.p1 - this.sym = this.sym === 'X' ? 'O' : 'X' + nextPlayer() { + this.player = this.player === this.p1 ? this.p2 : this.p1; + this.sym = this.sym === "X" ? "O" : "X"; } - hasWinner () { - return this.rowWin() || this.colWin() || this.diagWin() + hasWinner() { + return this.rowWin() || this.colWin() || this.diagWin(); } - rowWin () { - let win = false + rowWin() { + let win = false; for (let r = 0; r < 3; r++) { - const row = this.board[r] - if (row[0] === null) { continue } - win = win || (row[0] === row[1] && row[0] === row[2]) + const row = this.board[r]; + if (row[0] === null) { + continue; + } + win = win || (row[0] === row[1] && row[0] === row[2]); } - return win + return win; } - colWin () { - let win = false + colWin() { + let win = false; for (let c = 0; c < 3; c++) { - const col = this.board - if (col[0][c] === null) { continue } - win = win || (col[0][c] === col[1][c] && col[0][c] === col[2][c]) + const col = this.board; + if (col[0][c] === null) { + continue; + } + win = win || (col[0][c] === col[1][c] && col[0][c] === col[2][c]); } - return win + return win; } - diagWin () { - const b = this.board - return ((b[0][0] !== null && b[0][0] === b[1][1] && b[0][0] === b[2][2]) || - (b[0][2] !== null && b[0][2] === b[1][1] && b[0][2] === b[2][0])) + diagWin() { + const b = this.board; + return ( + (b[0][0] !== null && b[0][0] === b[1][1] && b[0][0] === b[2][2]) || + (b[0][2] !== null && b[0][2] === b[1][1] && b[0][2] === b[2][0]) + ); } } diff --git a/src/index.js b/src/index.js index 8faa426..4d09b20 100644 --- a/src/index.js +++ b/src/index.js @@ -1,60 +1,64 @@ -import Game from './game.js' +import Game from "./game.js"; -let p1, p2 +let p1, p2; while (!p1) { - p1 = window.prompt('Who is player 1?') + p1 = window.prompt("Who is player 1?"); } while (!p2 && p1 !== p2) { - p2 = window.prompt(p1 === p2 - ? `Please enter a different name than ${p1}.` - : 'Who is player 2?') + p2 = window.prompt( + p1 === p2 ? `Please enter a different name than ${p1}.` : "Who is player 2?" + ); } window.onload = () => { - document.getElementById('p1Name').innerText = p1 - document.getElementById('p2Name').innerText = p2 - let score1 = 0 + document.getElementById("p1Name").innerText = p1; + document.getElementById("p2Name").innerText = p2; + let score1 = 0; let score2 = 0; - (function playGame (p1, p2) { - document.getElementById('win').style.display = 'none' - document.getElementById('turn').style.display = 'inline' - document.getElementById('p1Score').innerText = score1 - document.getElementById('p2Score').innerText = score2 + (function playGame(p1, p2) { + document.getElementById("win").style.display = "none"; + document.getElementById("turn").style.display = "inline"; + document.getElementById("p1Score").innerText = score1; + document.getElementById("p2Score").innerText = score2; - const game = new Game(p1, p2) - const player = document.getElementById('player') - player.innerText = game.player + const game = new Game(p1, p2); + const player = document.getElementById("player"); + player.innerText = game.player; - document.querySelectorAll('#tictactoe td').forEach((el) => { - el.innerText = '' + document.querySelectorAll("#tictactoe td").forEach((el) => { + el.innerText = ""; el.onclick = (evt) => { - el.onclick = undefined - evt.target.innerText = game.sym - evt.target.onclick = undefined + el.onclick = undefined; + evt.target.innerText = game.sym; + evt.target.onclick = undefined; - const [row, col] = evt.target.classList - game.turn(row, col) + const [row, col] = evt.target.classList; + game.turn(row, col); if (game.hasWinner()) { - document.getElementById('winner').innerText = game.player - document.getElementById('win').style.display = 'inline' - document.getElementById('turn').style.display = 'none' + document.getElementById("winner").innerText = game.player; + document.getElementById("win").style.display = "inline"; + document.getElementById("turn").style.display = "none"; - if (game.player === p1) { document.getElementById('p1Score').innerText = ++score1 } else { document.getElementById('p2Score').innerText = ++score2 } + if (game.player === p1) { + document.getElementById("p1Score").innerText = ++score1; + } else { + document.getElementById("p2Score").innerText = ++score2; + } - document.getElementById('newGame').style.display = 'inline' - document.getElementById('newGame').onclick = () => playGame(p1, p2) + document.getElementById("newGame").style.display = "inline"; + document.getElementById("newGame").onclick = () => playGame(p1, p2); - document.querySelectorAll('td').forEach(el => { - el.onclick = undefined - }) + document.querySelectorAll("td").forEach((el) => { + el.onclick = undefined; + }); } else { - game.nextPlayer() - player.innerText = game.player + game.nextPlayer(); + player.innerText = game.player; } - } - }) - })(p1, p2) -} + }; + }); + })(p1, p2); +}; diff --git a/src/webpack.config.js b/src/webpack.config.js index 5300031..91e46e6 100644 --- a/src/webpack.config.js +++ b/src/webpack.config.js @@ -1,14 +1,14 @@ -const path = require('path') +const path = require("path"); module.exports = { entry: { - 'main.js': [ - path.resolve(__dirname, 'index.js'), - path.resolve(__dirname, 'game.js') - ] + "main.js": [ + path.resolve(__dirname, "index.js"), + path.resolve(__dirname, "game.js"), + ], }, output: { - filename: 'main.js', - path: path.resolve(__dirname, '../public') - } -} + filename: "main.js", + path: path.resolve(__dirname, "../public"), + }, +};