GitHub Action Documentation: Deploy Website
Created on July 08, 2023
Written by Some author
Read time: 3 minutes
Summary: The provided GitHub Action workflow automates the deployment of a website to an S3 bucket based on changes pushed to specific branches.
GitHub Action
Documentation: Deploy Website
This documentation provides an overview and explanation of the
GitHub Action you have created to deploy a website. The action is triggered
when a push event occurs on the main
branch or any branch that matches the pattern releases/**
. The purpose of this action is to deploy the
website files to an S3 bucket.
Workflow
File
The workflow file defines the configuration for your GitHub
Action. Here's an explanation of each section:
name: Deploy Website to
This
sets the name of your workflow.
on:
push:
branches:
- main
- 'releases/**'
This
specifies the trigger for your workflow. It will be triggered on push events to
the main
branch or any branch that matches the pattern releases/**
.
jobs:
deploy:
runs-on: ubuntu-latest
steps:
This
defines a job named deploy
that runs on an Ubuntu environment.
Steps
The steps section contains a series of actions that will be
executed sequentially during the job.
1. Checkout Repository
- uses: actions/checkout@v2
This
step uses the actions/checkout
action to clone your repository's
code into the runner's workspace.
2. Configure AWS Credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: "${{ secrets.AWS_ACCESS_KEY_ID
}}"
aws-secret-access-key: "${{ secrets.AWS_SECRET_ACCESS_KEY
}}"
aws-region: us-east-1
aws-default_output: json
This
step configures the AWS credentials required for accessing the AWS resources.
The access key ID and secret access key are read from the GitHub repository
secrets. The AWS region is set to us-east-1
, but you can change it to your desired region. The aws-default_output
is set to json
to ensure consistent output format.
3. Setup Python
# add python action
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
This
step sets up the Python environment by installing the specified Python version
(3.8 in this case). This allows you to run Python commands in subsequent steps.
4. Install Dependencies
# pip install
requirements.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
This
step installs the project's dependencies listed in the requirements.txt
file using pip
.
5. Build
# run build.py
- name: Build
run: |
python build.py
This
step runs the build.py
script, which is responsible for generating
the website files or performing any necessary build steps. Adjust the command
to match your specific build process.
6. List Files in Build Directory
# list all the files in the build directory
- name: List files in build directory
run: |
ls -R build/
This
step lists all the files in the build
directory. It helps you verify that the build process
generated the expected files.
7. Deploy to S3
- name: Deploy to S3
run: aws s3 sync
./build/ s3://somewhere/
--exclude "*.sh" --exclude
"generate/*"
This
step uses the AWS CLI (aws
) to synchronize the files in the local build
directory with the specified S3 bucket (s3://somewhere/
). The --exclude
flags are used to exclude files matching the
specified patterns. Adjust the S3 bucket path and exclusion patterns as needed.
Customization
To customize this GitHub Action for your specific use case, you
can make the following changes:
- Modify
the branch filters in the
on.push
.branches
section to match the branches you want to trigger the deployment. - Update
the AWS region (
aws
-region
) if you need to deploy to a different region. - Adjust
the Python version (
python-version
) in theactions/setup-python
step if your project requires a different version. - Modify
the command in the
Build
step (run: python build.py
) to match your specific build process. - Adjust
the S3 bucket path (
s3://somewhere/
) and exclusion patterns (--exclude
) in theDeploy to S3
step based on your S3 configuration and file requirements.
Remember to commit and push the changes to your repository to
trigger the workflow with the updated configuration.
That's it! You now have a GitHub Action that deploys your website
to an S3 bucket when changes are pushed to the specified branches.