Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run GitOps in dry-mode only on pull request #36

Merged
merged 1 commit into from
May 7, 2024
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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @getvictor, does this mean that if two contributor open a PR around the same time, only one contributor will get feedback from the dry run? (errors)

Sorry for the delayed response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should wait for the first dry run to finish before starting the other one. So, both contributors should get feedback.

This concurrency constraint was meant to prevent multiple real runs from running in parallel.

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
Loading