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 the main branch.

🔑 Permissions:

  • Grants write access to contents, enabling version updates in the repository.

📌 Job: build-and-push

  • 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.02.0.0).
    • [m]Minor version bump (e.g., 1.0.01.1.0).
    • [p]Patch version bump (e.g., 1.0.01.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 in helper_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:

  1. Checks out the repo.
  2. Reads the latest commit message to determine version increment.
  3. Runs a script to update the version.
  4. Logs into AWS ECR.
  5. Builds a Docker image, tags it with the new version, and pushes it.
  6. Tags and pushes the latest version.
  7. 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.