Skip to content

Commit

Permalink
Add D7ES Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pwtyler committed Dec 12, 2024
1 parent 03af2f4 commit 6d81f2a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/update_tag1_d7es.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -euo pipefail

main() {
# Variables
local MODULE_NAME="tag1_d7es"
local PANTHEON_UPSTREAM_DIR="modules/pantheon/$MODULE_NAME"
local PR_BASE_BRANCH="default"
local CURRENT_VERSION
local LATEST_VERSION
local TEMP_BRANCH
TEMP_BRANCH="update-$MODULE_NAME-$(date +%Y%m%d%H%M%S)"

# With these credentials, commits will be pushed to 'master' and available on
# the upstream immediately.
local GIT_USER="[email protected]"
local GIT_NAME="Pantheon Automation"

# TODO: Confirm if this domain needs to change in January
local RELEASE_HISTORY_URL="https://updates.drupal.org/release-history/${MODULE_NAME}/7.x"
LATEST_VERSION=$(curl -s "$RELEASE_HISTORY_URL" \
| grep -oE '<version>[0-9a-zA-Z\.\-]+' \
| sed 's/<version>//' \
| grep -vE '(-rc|-beta|-alpha)' \
| sort -V | tail -n 1
)

CURRENT_VERSION=$(grep '^version' "${PANTHEON_UPSTREAM_DIR}/tag1_d7es.info" \
| awk -F' = ' '{print $2}' | tr -d '"'
)

echo "Current: ${CURRENT_VERSION}"
echo "Latest: ${LATEST_VERSION}"

if [ "$LATEST_VERSION" == "$CURRENT_VERSION" ]; then
echo "Already up to date."
exit 0
fi

local PR_TITLE="Update $MODULE_NAME to version $LATEST_VERSION"
local PR_EXISTS
PR_EXISTS=$(gh pr list --state open --search "$LATEST_VERSION" --json title \
| jq --arg pr_title "$PR_TITLE" '.[] | select(.title | contains($pr_title))'
)

if [ -n "$PR_EXISTS" ]; then
echo "A PR for version $LATEST_VERSION already exists. Skipping PR creation."
exit 0
fi

git checkout -b "$TEMP_BRANCH"

# TODO: Confirm if this domain needs to change in January
local DRUPAL_ORG_FTP_GZ_URL="https://ftp.drupal.org/files/projects/$MODULE_NAME-$LATEST_VERSION.tar.gz"
wget -qO- "$DRUPAL_ORG_FTP_GZ_URL" | tar -xz -C /tmp

rsync -ar --delete "/tmp/$MODULE_NAME/" "$PANTHEON_UPSTREAM_DIR/"
rm -rf "$PANTHEON_UPSTREAM_DIR/.github"
rm -f "$PANTHEON_UPSTREAM_DIR/.gitlab-ci.yml"
rm -rf "$PANTHEON_UPSTREAM_DIR/tests"

git config user.email "${GIT_USER}"
git config user.name "${GIT_NAME}"

git add "$PANTHEON_UPSTREAM_DIR"
git commit -m "Update $MODULE_NAME to version $LATEST_VERSION"
git push origin "$TEMP_BRANCH"

local PR_BODY="Updates the $MODULE_NAME module to version $LATEST_VERSION."
gh pr create --title "$PR_TITLE" \
--body "$PR_BODY" \
--head "$TEMP_BRANCH" \
--base "$PR_BASE_BRANCH"
}

main
24 changes: 24 additions & 0 deletions .github/workflows/update_tag1_d7es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
workflow_dispatch:

permissions:
pull-requests: write
contents: write

jobs:
check-update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq wget curl
- name: Check and Update Module
run: .github/update_tag1_d7es.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1 comment on commit 6d81f2a

@pantheon-ci-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Visit Site

Created multidev environment ci-556 for ci-update-drops-7.

Please sign in to comment.