Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ModeSevenIndustrialSolutions authored Apr 25, 2024
2 parents 73ec08d + aadf0cb commit 0a9dfd7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 38 deletions.
87 changes: 58 additions & 29 deletions .github/workflows/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
GH_TOKEN: ${{ github.token }}
# yamllint disable rule:line-length
run: |
### SHELL CODE START ###
#SHELLCODESTART
set -euo pipefail
# set -x
Expand All @@ -55,11 +55,22 @@ jobs:
# Define functions
perform_folder_operation() {
FS_PATH="$1"
if [ -d "$DEVOPS_DIR"/"$FS_PATH" ]; then
echo "Scanning target folder content at: $FS_PATH"
return 0
else
echo "Upstream folder NOT found: $FS_PATH [skipping]"
return 1
fi
}
# Allows for selective opt-out components on a per-path basis
perform_operation() {
FS_PATH="$1"
if [ ! -f "$FS_PATH" ] && [ ! -d "$FS_PATH" ]; then
echo "Skipping missing upstream element at: $FS_PATH"
if [ ! -f "$DEVOPS_DIR"/"$FS_PATH" ]; then
echo "Skipping missing upstream file at: $FS_PATH"
return 1
fi
# Elements excluded from processing return exit status 1
Expand Down Expand Up @@ -113,7 +124,7 @@ jobs:
fi
}
check_authors() {
check_prs() {
# Define users to check for pre-existing pull requests
AUTOMATION_USER="github-actions[bot]"
if [[ -n ${GH_TOKEN+x} ]]; then
Expand All @@ -137,6 +148,29 @@ jobs:
echo "Failed to checkout pull request"; exit 1
fi
done
return 1
}
# Check if script is running in GHA workflow
in_github() {
if [ -z ${GITHUB_RUN_ID+x} ]; then
echo "Script is NOT running in GitHub"
return 1
else
echo "Script is running in GitHub"
return 0
fi
}
# Check if user is logged into GitHub
logged_in_github() {
if (gh auth status); then
echo "Logged in and authenticated to GitHb"
return 0
else
echo "Not logged into GitHub, some script operations unavailable"
return 1
fi
}
# Main script entry point
Expand All @@ -159,24 +193,6 @@ jobs:
# git stash -q
# fi
# Verify user is logged into GitHub
if (gh auth status); then
GH_AUTH="true"
else
echo "Not logged into GitHub, some script operations unavailable"
GH_AUTH="false"
fi
if [ "$GH_AUTH" = "true" ] && ! (check_authors); then
# No existing open pull requests found for this repository
echo "Removing remote branch if it exists: $AUTOMATION_BRANCH"
git push origin --delete "$AUTOMATION_BRANCH" > /dev/null 2>&1 || :
git branch -D "$AUTOMATION_BRANCH" || :
fi
echo "Creating local branch for automated update"
git checkout -b "$AUTOMATION_BRANCH"
# Configure GIT environment only if NOT already configured
# i.e. when running in a GitHub Actions workflow
TEST=$(git config -l > /dev/null 2>&1)
Expand All @@ -186,14 +202,26 @@ jobs:
"41898282+github-actions[bot]@users.noreply.github.com"
fi
if ! (check_prs); then
# No existing open pull requests found for this repository
# Remove remote branch if it exists
git push origin --delete "$AUTOMATION_BRANCH" > /dev/null 2>&1 || :
git branch -D "$AUTOMATION_BRANCH" || :
git checkout -b "$AUTOMATION_BRANCH"
else
# The -B flag swaps branch and creates it if NOT present
git checkout -B "$AUTOMATION_BRANCH"
fi
# Only if NOT running in GitHub
# (checkout is otherwise performed by earlier steps)
if [ -z ${GITHUB_RUN_ID+x} ]; then
if ! (in_github); then
# Remove any stale local copy of the upstream repository
if [ -d "$DEVOPS_DIR" ]; then
rm -Rf "$DEVOPS_DIR"
fi
printf "Cloning DevOps repository into: %s" "$DEVOPS_DIR"
if (git clone "$DEVOPS_REPO" "$DEVOPS_DIR" > /dev/null 2>&1); then
echo " [success]"
Expand All @@ -220,7 +248,7 @@ jobs:
for FOLDER in "${LINE[@]}";
do
# Check to see if this folder should be skipped
if (perform_operation "$FOLDER"); then
if (perform_folder_operation "$FOLDER"); then
# If necessary, create target folder
if [ ! -d "$FOLDER" ]; then
echo "Creating target folder: $FOLDER"
Expand Down Expand Up @@ -267,13 +295,14 @@ jobs:
echo "branchname=$AUTOMATION_BRANCH" >> "$GITHUB_OUTPUT"
echo "headbranch=$HEAD_BRANCH" >> "$GITHUB_OUTPUT"
# Move to the next workflow step to raise the PR
git push --set-upstream origin "$AUTOMATION_BRANCH"
exit 0
fi
# If running shell code locally, continue to raise the PR
# Reinstate exit on unbound variables
set -euxo pipefail
set -euo pipefail
git status
if ! (git commit -as -S -m "Chore: Update DevOps tooling from central repository [skip ci]" \
Expand All @@ -289,13 +318,13 @@ jobs:
fi
# echo "Unstashing unstaged changes, if any exist"
# git stash pop -q || :
### SHELL CODE END ###
#SHELLCODEEND
- name: Create Pull Request
if: steps.update-repository.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
env:
GITHUB_TOKEN: ${{ github.token }}
# env:
# GITHUB_TOKEN: ${{ github.token }}
with:
# Note: Requires a specific/defined Personal Access Token
token: ${{ secrets.ACTIONS_WORKFLOW }}
Expand Down
24 changes: 18 additions & 6 deletions .github/workflows/builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: "Install dependencies"
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: "Setup PDM for build commands"
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}

- name: "Tag for test release"
# Delete all local tags, then create a synthetic tag for testing
Expand All @@ -62,6 +62,18 @@ jobs:
git checkout "tags/v${{ steps.setenv.outputs.vernum }}"
grep version pyproject.toml
- name: "Build with TOX"
- name: "Performing build"
run: |
tox -e build
PDM_CMD=$(which pdm)
if [ -f tox.ini ]; then
python -m pip install --upgrade pip
pip install tox tox-gh-actions
echo "Building with command: tox -e build"
tox -e build
elif [ -x "$PDM_CMD" ]; then
echo "Building with command: pdm build"
pdm build
else
echo "Building with command: python -m build"
python -m build
fi
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ repos:
rev: v1.35.1
hooks:
- id: yamllint
args: [--strict]
args: [
"-d",
"{rules: {line-length: {max: 120}},
ignore-from-file: [.gitignore],
}",
]

- repo: https://github.com/Mateusz-Grzelinski/actionlint-py
rev: v1.6.27.13
Expand Down
4 changes: 2 additions & 2 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ echo " $WGET_URL"
echo "Extracting shell code from: $SOURCE_FILE"
EXTRACT="false"
while read -r LINE; do
if [ "$LINE" = "### SHELL CODE START ###" ]; then
if [ "$LINE" = "#SHELLCODESTART" ]; then
EXTRACT="true"
SHELL_SCRIPT=$(mktemp -t script-XXXXXXXX.sh)
touch "$SHELL_SCRIPT"
Expand All @@ -113,7 +113,7 @@ while read -r LINE; do
fi
if [ "$EXTRACT" = "true" ]; then
echo "$LINE" >> "$SHELL_SCRIPT"
if [ "$LINE" = "### SHELL CODE END ###" ]; then
if [ "$LINE" = "#SHELLCODEEND" ]; then
break
fi
fi
Expand Down

0 comments on commit 0a9dfd7

Please sign in to comment.