Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 138 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI/CD Pipeline

on:
push:
Expand All @@ -13,7 +13,6 @@ on:
- README.md
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight
# Allow manual triggering of the workflow
workflow_dispatch:
inputs:
force:
Expand All @@ -23,29 +22,157 @@ on:
type: boolean

jobs:
build:
# ============================================
# Stage 1: Validation (runs in parallel)
# ============================================

script-validation:
name: Script Validation
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install shellcheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck

- name: Run shellcheck on scripts
run: find scripts/ -name "*.sh" -exec shellcheck {} \;

- name: Validate script syntax
run: find scripts/ -name "*.sh" -exec bash -n {} \;

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install bats-core
run: |
git clone https://github.com/bats-core/bats-core.git /tmp/bats-core
cd /tmp/bats-core
sudo ./install.sh /usr/local

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y curl jq

- name: Make scripts executable
run: chmod +x scripts/*.sh

- name: Run unit tests
run: bats tests/unit/

# ============================================
# Stage 2: Build Test Image (after validation)
# ============================================

build-test-image:
name: Build Test Image
runs-on: ubuntu-latest
needs: [unit-tests, script-validation]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up environment variables
id: get-net-pwsh-versions
run: |
# Generate /tmp/env_vars by running the script directly
chmod +x ./scripts/get-net-pwsh-versions.sh
./scripts/get-net-pwsh-versions.sh
# Set BUILD_ARGS as a multiline env var directly from /tmp/env_vars
echo "BUILD_ARGS<<EOF" >> $GITHUB_ENV
cat /tmp/env_vars >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Debug output to verify
echo "Build args prepared:"
cat /tmp/env_vars

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image (no push)
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: jmcombs/powershell:test
platforms: linux/amd64
build-args: ${{ env.BUILD_ARGS }}

- name: Save Docker image as artifact
run: docker save jmcombs/powershell:test -o /tmp/test-image.tar

- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: test-image
path: /tmp/test-image.tar
retention-days: 1

# ============================================
# Stage 3: Integration Tests (using test image)
# ============================================

integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: build-test-image
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: test-image
path: /tmp

- name: Load Docker image
run: |
docker load -i /tmp/test-image.tar
# Tag as :latest so integration tests can find it
docker tag jmcombs/powershell:test jmcombs/powershell:latest
echo "Available Docker images:"
docker images | grep powershell

- name: Install bats-core
run: |
git clone https://github.com/bats-core/bats-core.git /tmp/bats-core
cd /tmp/bats-core
sudo ./install.sh /usr/local

- name: Run integration tests
env:
CI: true
run: bats tests/integration/

# ============================================
# Stage 4: Publish (only on main, after tests)
# ============================================

publish:
name: Build and Publish
runs-on: ubuntu-latest
needs: integration-tests
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up environment variables
run: |
chmod +x ./scripts/get-net-pwsh-versions.sh
./scripts/get-net-pwsh-versions.sh
echo "BUILD_ARGS<<EOF" >> $GITHUB_ENV
cat /tmp/env_vars >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand Down Expand Up @@ -83,51 +210,21 @@ jobs:

- name: Update README with versions
run: |
# Extract versions from environment variables
NET_RUNTIME_LTS_VERSION=$(grep 'NET_RUNTIME_LTS_VERSION' /tmp/env_vars | cut -d '=' -f 2)
PWSH_LTS_VERSION=$(grep 'PWSH_LTS_VERSION' /tmp/env_vars | cut -d '=' -f 2)

# Set as environment variables for later steps
echo "NET_RUNTIME_LTS_VERSION=$NET_RUNTIME_LTS_VERSION" >> $GITHUB_ENV
echo "PWSH_LTS_VERSION=$PWSH_LTS_VERSION" >> $GITHUB_ENV

# Debug: Show current versions and what we're updating to
echo "Current .NET Core Runtime version in README:"
grep "| .NET Core Runtime |" README.md || echo "Pattern not found"
echo "Current PowerShell Core version in README:"
grep "| PowerShell Core" README.md || echo "Pattern not found"
echo "New .NET Core Runtime version: $NET_RUNTIME_LTS_VERSION"
echo "New PowerShell Core version: $PWSH_LTS_VERSION"

# Update README.md with the extracted versions (fixed spacing)
sed -i "s/| .NET Core Runtime | .*/| .NET Core Runtime | $NET_RUNTIME_LTS_VERSION |/" README.md
sed -i "s/| PowerShell Core | .*/| PowerShell Core | $PWSH_LTS_VERSION |/" README.md

# Verify the changes were made
echo "Updated README versions:"
grep -A 2 "| Component" README.md

- name: Check for changes
id: verify-changed-files
run: |
if git diff --quiet README.md; then
echo "No changes to README.md"
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in README.md"
echo "changed=true" >> $GITHUB_OUTPUT
git diff README.md
fi

- name: Commit and push changes
if: steps.verify-changed-files.outputs.changed == 'true'
- name: Commit version updates
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update README.md with latest .NET Core Runtime and PowerShell Core versions"
branch: main
file_pattern: README.md

- name: Update README on Docker
- name: Update README on Docker Hub
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand Down
Loading