In this post, I will guide you through setting up GitHub actions to deploy any static site to surge. Before we begin, let’s talk about GitHub action and surge. What are they?
GitHub Actions is a continuous integration and delivery (CI/CD) tool for the GitHub flow. It is capable of integrating and deploying code changes to a third-party cloud application platform, as well as testing, tracking, and managing code changes. Third-party CI/CD technologies, the container platform Docker, and other automation platforms are also supported by GitHub Actions.
Surge is a free static website host which you interact with from your command line. It makes it quick and easy to get new sites and apps online, either manually or as part of your CI build process.
- You should have a GitHub account.
- You should have a surge account. step by step guide
- You should have a static website.
Create a new surge account
If you don’t have a surge account, you can create one by following the steps below. It can be done from your command line.
- Install surge by running the following command in your terminal.
npm install --global surge
- Run the following command to login to surge.
- Enter your email address and password when prompted.
- You will receive a verification email. Click on the link in the email to verify your email address.
- You are now logged in to surge.
Generating a surge token
- In a command line, run the following command to generate a surge token.
Setting up the GitHub action
- Go to the GitHub repository where you want to set up the GitHub action.
- Add a new file to the repository. Name the file
deploy.ymlon the path
- Add the following code to the file.
name: Deploy to surge on: push: branches: - master # Set a branch to deploy jobs: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - name: Use Node.js 14.x uses: actions/[email protected] with: node-version: 14.x # Install dependencies - name: Install dependencies run: npm install # Build the project - name: Build run: npm run build # Deploy to surge - name: Deploy run: npm install --global surge run: surge ./build <your_url_to_deploy> --token <your_surge_token>
Reading token from GitHub secrets
You can also read the surge token from GitHub secrets. This is a more secure way to store the token. To do this, follow the steps below.
Go to the GitHub repository where you want to set up the GitHub action.
Go to the settings of the repository.
Go to the secrets section.
Add a new secret. Name the secret
SURGE_TOKEN. Paste the surge token in the value field.