-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pr-lock action * chore: make some change to trigger workflow * chore: tidy up the repo * chore(ansible-lint): change the action i used to the maintained one * fix: linting * test: upgrade ansible * fix: use ansible requirements file * fix: order issue with the action * fix: local action path * fix: create branch id doesn't exist * test: create orphan branch * fix: orpahn branch creation * chore: refact the lock mechanism * fix: do not push the lock right away * fix: configure commit author * chore: move the lock out of the run-playbook * fis: properly handle case where lock already exist * fix: ansible must install modules * fix: missing then in workflow script
- Loading branch information
Showing
19 changed files
with
167 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: 'PR Lock' | ||
description: 'Ensure that only one PR can deploy at a time using a lock file mechanism.' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Create or checkout lock branch | ||
shell: bash | ||
run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
# Fetch the lock-branch if it exists, otherwise handle the failure | ||
if git fetch origin lock-branch; then | ||
echo "Lock branch exists. Checking out." | ||
git checkout lock-branch | ||
else | ||
echo "Lock branch does not exist. Creating a new one." | ||
git checkout --orphan lock-branch | ||
git rm -rf . | ||
git clean -fdx | ||
git commit --allow-empty -m "Initialize lock branch" | ||
fi | ||
- name: Check for lock file | ||
id: check-lock | ||
shell: bash | ||
run: | | ||
if [ -f ".deploy-lock" ]; then | ||
# Read the PR number from the lock file | ||
LOCKED_PR=$(cat .deploy-lock) | ||
# Compare it with the current PR number | ||
if [ "$LOCKED_PR" != "${{ github.event.pull_request.number }}" ]; then | ||
echo "Another deployment is in progress by PR #$LOCKED_PR. Exiting..." | ||
exit 1 | ||
else | ||
echo "Current PR #${{ github.event.pull_request.number }} already holds the lock. Proceeding with deployment." | ||
fi | ||
else | ||
echo "No lock file found. Creating lock file.." | ||
echo "${{ github.event.pull_request.number }}" > .deploy-lock | ||
git add .deploy-lock | ||
git commit -m "Lock deployment for PR #${{ github.event.pull_request.number }}" | ||
git push origin lock-branch | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'PR Lock Remove' | ||
description: 'Remove the deployment lock file after deployment on the main branch.' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Checkout lock branch | ||
shell: bash | ||
run: | | ||
git fetch origin lock-branch | ||
git checkout lock-branch || git checkout --orphan lock-branch | ||
- name: Remove lock file | ||
id: remove-lock | ||
shell: bash | ||
run: | | ||
if [ -f ".deploy-lock" ]; then | ||
echo "Removing lock file..." | ||
git rm .deploy-lock | ||
git config user.name "github-actions" | ||
git config user.email "[email protected]" | ||
git commit -m "Unlock deployment" | ||
git push origin lock-branch | ||
else | ||
echo "No lock file found." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ on: | |
- synchronize | ||
paths: | ||
- 'ansible/**' | ||
- requirements.txt | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
@@ -29,37 +30,53 @@ jobs: | |
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run ansible-lint | ||
# replace `main` with any valid ref, or tags like `v6` | ||
uses: ansible-community/[email protected] | ||
uses: ansible/[email protected] # or version tag instead of 'main' | ||
with: | ||
args: "ansible" | ||
|
||
lock: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
# Lock if this is a PR so two PR cannot deploy at the same time | ||
- name: PR Lock | ||
if: github.event_name == 'pull_request' | ||
uses: ./.github/actions/pr-lock | ||
|
||
- name: Clear PR Lock | ||
if: github.ref == 'refs/heads/main' | ||
uses: ./.github/actions/pr-unlock | ||
|
||
run-playbook: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
# The validate Job need to be sucessfull | ||
needs: [ validate ] | ||
needs: [ validate, lock ] | ||
# The deployement environnement thus provides the secrets for that env | ||
environment: digitalocean | ||
|
||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.9 | ||
# Setup the environment | ||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
python-version: "3.12" | ||
cache: 'pip' # caching pip dependencies | ||
|
||
- name: Install dependencies Including Ansible | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi | ||
if [ -f requirements.yml ]; then ansible-galaxy install -r requirements.yml; fi | ||
- name: write inventory to file | ||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
copy: | ||
content: hello-world | ||
dest: /tmp/testfile.txt | ||
mode: 0644 | ||
mode: "0644" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
copy: | ||
content: hello-world | ||
dest: /tmp/testfile.txt | ||
mode: 0644 | ||
mode: "0644" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.