GitHub Workflow Description - Campus-Castolo/m300 GitHub Wiki
🛠 Workflow Name:
"Build and Push WP Image to ECR with Semantic Tagging"
🎯 Trigger:
- Runs only on
push
events to themain
branch.
🔑 Permissions:
- Grants write access to contents, enabling version updates in the repository.
build-and-push
📌 Job: - Runs on Ubuntu (latest version).
1️⃣ Checkout Repository
- Uses
actions/checkout@v4
to clone the repository. fetch-depth: 0
ensures full commit history is available (needed for versioning).
2️⃣ Determine Version Increment
- Extracts the latest commit message and checks for versioning indicators:
[M]
→ Major version bump (e.g.,1.0.0
→2.0.0
).[m]
→ Minor version bump (e.g.,1.0.0
→1.1.0
).[p]
→ Patch version bump (e.g.,1.0.0
→1.0.1
).
- If none of these tags are found, the workflow exits with an error.
3️⃣ Increment Git Version
- Runs
git_update.sh
(a custom script inhelper_script/
) to bump the version based on the detected increment. - Stores the new version number in
GITHUB_OUTPUT
for later steps.
4️⃣ Configure AWS Credentials
- Uses
aws-actions/configure-aws-credentials@v4
to authenticate with AWS using secrets stored in GitHub:${{ secrets.AWS_ACCESS_KEY_ID }}
${{ secrets.AWS_SECRET_ACCESS_KEY }}
${{ secrets.AWS_SESSION_TOKEN }}
- Sets the AWS region to us-east-1.
5️⃣ Login to Amazon ECR
- Uses
aws-actions/amazon-ecr-login@v2
to authenticate with AWS ECR and get the ECR registry URL.
6️⃣ Build, Tag, and Push Docker Image
- Builds a Docker image from
.wp-build/Dockerfile
. - Tags the image with:
- The ECR registry URL.
- The repository name (
m300/m300
). - The new version tag (from the earlier step).
- Pushes the newly tagged image to ECR.
7️⃣ Push Latest Tag
- Tags the latest built image as
latest
. - Pushes the
latest
tag to ECR (ensuring that the most recent build is always available under:latest
).
8️⃣ Commit Updated Version
- Configures Git to use GitHub Actions bot for committing.
- Adds the updated
VERSION
file to Git. - Commits the new version with a message like:
Bump version to X.Y.Z
- Pushes the commit back to the
main
branch.
💡 Summary:
- Checks out the repo.
- Reads the latest commit message to determine version increment.
- Runs a script to update the version.
- Logs into AWS ECR.
- Builds a Docker image, tags it with the new version, and pushes it.
- Tags and pushes the
latest
version. - Commits the updated version file back to the repository.
The workflow ensures automated versioning, image building, and deployment with semantic version tagging based on commit messages.