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

[Enabler][692] Add a command that checks the changelog into ac and create a GitHub action #1422

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
33 changes: 33 additions & 0 deletions .github/workflows/ac-check-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: AC Check Changelog

on:
pull_request:
branches:
- dev
- staging*

IsaacVRey marked this conversation as resolved.
Show resolved Hide resolved
jobs:
check-changelog:
runs-on: ubuntu-latest
env:
PR_BASE: ${{ github.event.pull_request.base.ref }}
PR_HEAD: ${{ github.event.pull_request.head.ref }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Set up venv
run: |
python -m pip install --upgrade pip
pip install virtualenv
mkdir venv
virtualenv venv/venv-2.16

- name: Run ac-check-changelog
run: |
./ac --ac-check-changelog --base "$PR_BASE" --head origin/"$PR_HEAD"
72 changes: 54 additions & 18 deletions ac
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,6 @@ ac_build(){
}

# ------------------------------------------------------------------------------
# Run galaxy importer on collection.
# ------------------------------------------------------------------------------
#->ac-galaxy-importer:
## Build current branch and run galaxy importer on collection.
## Usage: ac [--ac-galaxy-importer]
## Example:
## $ ac --ac-galaxy-importer
ac_galaxy_importer(){
message "Running Galaxy Importer"
. $VENV_BIN/activate && collection_name=$($VENV_BIN/ansible-galaxy collection build --force | awk -F/ '{print $NF}') && python -m galaxy_importer.main $collection_name
}

# Run a changelog lint locally
# ------------------------------------------------------------------------------
#->ac-changelog:
Expand All @@ -279,6 +267,38 @@ ac_changelog(){
. $VENV_BIN/activate && antsibull-changelog "${option_command}"
}

# Check for new files in the changelog.
# Comparing it to another branch.
# ------------------------------------------------------------------------------
#->ac-check-changelog:
## Check for new files in the changelog.
## Usage: ac [--ac-check-changelog <base> <head>]
## <base> - Branch to compare with
## <head> - This branch
## Example:
## $ ac-check-changelog --base dev --head test
ac_check_changelog(){
option_base=$1
option_head=$2
if [ ! "$option_base" ]; then
option_base="dev"
fi
message "Check for new files in the changelog."
. $VENV_BIN/activate && git fetch && git checkout origin/"$option_base" && cd changelogs/fragments/ && LS_BASE="$(ls)" && cd .. && cd .. && git checkout "$option_head" ./changelogs/fragments/ && cd changelogs/fragments/ && LS_ALL="$(ls)" && git checkout "$option_head" && [ "${#LS_ALL}" -gt "${#LS_BASE}" ] || (echo "No new changelog file was found" && return 1) #echo $VAR && [ "$VAR" != "No new changelog file was found" ] ||
}

# Run galaxy importer on collection.
# ------------------------------------------------------------------------------
#->ac-galaxy-importer:
## Build current branch and run galaxy importer on collection.
## Usage: ac [--ac-galaxy-importer]
## Example:
## $ ac --ac-galaxy-importer
ac_galaxy_importer(){
message "Running Galaxy Importer"
. $VENV_BIN/activate && collection_name=$($VENV_BIN/ansible-galaxy collection build --force | awk -F/ '{print $NF}') && python -m galaxy_importer.main $collection_name
}

# ------------------------------------------------------------------------------
# Install an ibm_zos_core collection from galaxy (or how you have ansible.cfg configured)
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -691,14 +711,18 @@ while true; do
ensure_managed_venv_exists $1
option_submitted="--ac-build"
;;
--ac-galaxy-importer) # Command
ensure_managed_venv_exists $1
option_submitted="--ac-galaxy-importer"
;;
--ac-changelog) # Command
ensure_managed_venv_exists $1
option_submitted="--ac-changelog"
;;
--ac-check-changelog) # Command
ensure_managed_venv_exists $1
option_submitted="--ac-check-changelog"
;;
--ac-galaxy-importer) # Command
ensure_managed_venv_exists $1
option_submitted="--ac-galaxy-importer"
;;
--ac-install)
ensure_managed_venv_exists $1 # Command
option_submitted="--ac-install"
Expand Down Expand Up @@ -762,6 +786,11 @@ while true; do
ensure_managed_venv_exists $1
option_submitted="--venv-stop"
;;
--base|--base=?*) # option
base=`option_processor $1 $2`
option_sanitize $base
shift
;;
--command|--command=?*) # option
command=`option_processor $1 $2`
option_sanitize $command
Expand All @@ -777,6 +806,11 @@ while true; do
option_sanitize $file
shift
;;
--head|--head=?*) # option
head=`option_processor $1 $2`
option_sanitize $head
shift
;;
--host|--host=?*) # option
host=`option_processor $1 $2`
option_sanitize $host
Expand Down Expand Up @@ -851,10 +885,12 @@ if [ "$option_submitted" ] && [ "$option_submitted" = "--ac-bandit" ] ; then
ac_bandit $level
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-build" ] ; then
ac_build
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-galaxy-importer" ] ; then
ac_galaxy_importer
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-changelog" ] ; then
ac_changelog $command
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-check-changelog" ] ; then
ac_check_changelog $base $head
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-galaxy-importer" ] ; then
ac_galaxy_importer
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-install" ] ; then
ac_install $version
elif [ "$option_submitted" ] && [ "$option_submitted" = "--ac-lint" ] ; then
Expand Down
Loading