Skip to content

Commit

Permalink
Dry-run only on PR (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed May 7, 2024
1 parent f584d8c commit c039381
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/gitops-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
working-directory:
description: 'The working directory, which should be the root of the fleet-gitops repository.'
default: './'
dry-run-only:
description: 'Whether to only run the fleetctl gitops commands in dry-run mode.'
default: 'false'

runs:
using: "composite"
Expand All @@ -22,4 +25,6 @@ runs:
- name: Run fleetctl gitops commands
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }}
run: ./gitops.sh
9 changes: 9 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch: # allows manual triggering

# Prevent concurrent runs of this workflow.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

defaults:
run:
shell: bash
Expand All @@ -23,6 +29,9 @@ jobs:

- name: Apply latest configuration to Fleet
uses: ./.github/gitops-action
with:
# Run GitOps in dry-run mode for pull requests.
dry-run-only: ${{ github.event_name == 'pull_request' && 'true' || 'false' }}
# Add FLEET_URL and FLEET_API_TOKEN to the repository secrets.
# In addition, specify or add secrets for all the environment variables that are mentioned in the global/team YAML files.
env:
Expand Down
4 changes: 4 additions & 0 deletions gitops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -exuo pipefail
FLEET_GITOPS_DIR="${FLEET_GITOPS_DIR:-./}"
FLEET_GLOBAL_FILE="${FLEET_GLOBAL_FILE:-$FLEET_GITOPS_DIR/default.yml}"
FLEETCTL="${FLEETCTL:-fleetctl}"
FLEET_DRY_RUN_ONLY="${FLEET_DRY_RUN_ONLY:-false}"

# Validate that global file contains org_settings
grep -Exq "^org_settings:.*" "$FLEET_GLOBAL_FILE"
Expand All @@ -26,6 +27,9 @@ for team_file in "$FLEET_GITOPS_DIR"/teams/*.yml; do
$FLEETCTL gitops -f "$team_file" --dry-run
fi
done
if [ "$FLEET_DRY_RUN_ONLY" = true ]; then
exit 0
fi

# Real run
$FLEETCTL gitops -f "$FLEET_GLOBAL_FILE"
Expand Down

0 comments on commit c039381

Please sign in to comment.