Automate your deployments with GitHub Actions
Category: DevOps
Learn how to use GitHub Actions to automate your deployments. Learn how to set up a CI/CD pipeline that builds, tests, and deploys your application on every push. main.
Featured Image (search Envato Elements):
developer devops automation ci cd pipeline github concept
Add “isometric” if you prefer vector illustrations.
What is GitHub Actions?
GitHub Actions is a GitHub-native automation platform that allows you to define custom workflows that run based on events (such as a push, pull request either release). You can use it for:
- Run tests automatically
- Compile and package your code
- Deploy to production without manual intervention
All of this is defined by YAML files in the directory .github/workflows.
Step 1: Create the basic workflow
Create the directory .github/workflows in your repository and add a file deploy.yml with this basic content:
name: CI/CD Pipeline on: push: branches: - main jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Clone repository uses: actions/checkout@v3 - name: Install Java uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - name: Build project run: ./mvnw clean install - name: Build image Docker run: docker build -t myapp:latest . - name: Login to Docker Hub run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin - name: Upload image run: docker tag myapp:latest docker.io/youruser/myapp:latest && docker push docker.io/youruser/myapp:latest
⚠️ Remember: Configure credentials DOCKER_USERNAME and DOCKER_PASSWORD in the secrets from the repository.
Step 2: Add the deployment step
Let's say you have a remote server where you want to deploy your container. You can use scp and ssh to copy the docker-compose.yml and release the new version:
- name: Copy files to server run: | scp docker-compose.yml user@server-ip:/home/user/app ssh user@server-ip 'cd /home/user/app && docker-compose pull && docker-compose up -d'
And add the necessary SSH keys like secrets (SSH_PRIVATE_KEY) and configure them before running the commands:
- name: Configure SSH uses: webfactory/ssh-agent@v0.8.0 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
Step 3: Additional improvements
- Running tests before compiling
- Notifications to Slack or Discord upon completion
- Deployments to multiple environments (
staging,production) - Manual review before deployment (
workflow_dispatch) - Reusing jobs with
reusable workflows
Advantages of using GitHub Actions
- ✔️ Direct integration with your repository
- 🔄 Guaranteed repeatability with every deployment
- 📈 Continuous improvement in quality and speed
- 🔒 Secure management of secrets and keys
Conclusion
GitHub Actions lets you automate everything from the most basic steps to complete CI/CD workflows with productive deployments. Mastering this tool is key for any modern developer looking for efficiency and professionalism in their deliveries.
Start with a simple flow and evolve into robust pipelines with validations, multiple environments, and continuous deployment. Automation isn't the future, it's the present.





