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

Test of GitHub actions #3

Closed
wants to merge 19 commits into from
Closed
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
43 changes: 43 additions & 0 deletions .github/actions/initial-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Initial Setup

runs:
using: "composite"
steps:
- name: Print initial state
run: |
echo -e "GitHub workspace:${{ github.workspace }}"
echo "Current directory:"
pwd
echo "Contents of /etc/hosts:"
cat /etc/hosts
echo "Owner of /etc/hosts:"
ls -l /etc/hosts
echo "Current user:"
whoami
shell: bash

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

# 8.2+ is expected for php-code-quality-tests
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, opcache

- name: Install Composer
run: |
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
shell: bash

- name: Run install-tools.sh
run: bash ${{ github.workspace }}/tools/install-tools.sh
shell: bash

- name: Build assets
run: cd ${{ github.workspace }}/assets && yarn build:all
shell: bash
42 changes: 42 additions & 0 deletions .github/actions/release/svn-make-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: SVN Make Commit

inputs:
username:
description: "SVN account username to make a commit"
required: true
password:
description: "SVN account password to make a commit"
required: true
tag:
description: "Current release tag"
required: true

runs:
using: "composite"
steps:
- name: Handle removed items in the trunk folder
run: |
# Check for removed files and handle them
REMOVED_FILES=$(svn status | awk '/^\!/ {print $2}')
if [ -n "$REMOVED_FILES" ]; then
echo "Found removed files:"
echo "$REMOVED_FILES"
echo "$REMOVED_FILES" | sort -r | xargs -r svn delete
else
echo "No removed files to handle."
fi
working-directory: ${{ github.workspace }}/release/trunk
shell: bash

- name: Add new folders and files
run: |
svn add --force ${{ github.workspace }}/release/trunk
svn add --force ${{ github.workspace }}/release/assets/*
svn add ${{ github.workspace }}/release/tags/${{ inputs.tag }}
shell: bash

- name: Commit changes
run: |
cd ${{ github.workspace }}/release
svn ci -m "v ${{ inputs.tag }}" --config-option=servers:global:http-timeout=900 --non-interactive --no-auth-cache --username ${{ inputs.username }} --password ${{ inputs.password }}
shell: bash
63 changes: 63 additions & 0 deletions .github/actions/release/svn-prepare-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: SVN Prepare Commit

outputs:
release_tag:
description: "Current release tag"
value: ${{ steps.get_tag.outputs.version }}

runs:
using: "composite"
steps:
- name: Get tag
id: get_tag
run: |
VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${VERSION#v}"
echo "::set-output name=version::$VERSION"
shell: bash

- name: Print tag
run: |
echo "Tag: ${{ steps.get_tag.outputs.version }}"
shell: bash

- name: Make release folder
run: mkdir ${{ github.workspace }}/release
shell: bash

- name: Init SVN
run: svn co https://plugins.svn.wordpress.org/prosopo-procaptcha ${{ github.workspace }}/release
shell: bash

- name: Make sure the tag does not exist
run: |
set -e # Exit immediately if a command exits with a non-zero status
cd ${{ github.workspace }}/release
# Check if the tag already exists
if svn ls tags | grep -q ${{ steps.get_tag.outputs.version }}; then
echo "Tag ${{ steps.get_tag.outputs.version }} already exists."
exit 1
else
echo "Tag ${{ steps.get_tag.outputs.version }} does not exist."
fi
shell: bash

- name: Copy assets
run: cp ${{ github.workspace }}/wordpress-org-assets/* ${{ github.workspace }}/release/assets
shell: bash

- name: Create the target Tag folder
run: mkdir ${{ github.workspace }}/release/tags/${{ steps.get_tag.outputs.version }}
shell: bash

- name: Copy files to the new Tag folder
run: cp -r ${{ github.workspace }}/prosopo-procaptcha/* ${{ github.workspace }}/release/tags/${{ steps.get_tag.outputs.version }}
shell: bash

- name: Empty Trunk folder
run: rm ${{ github.workspace }}/release/trunk/* -rf
shell: bash

- name: Copy files and folders to the Trunk folder
run: cp -r ${{ github.workspace }}/prosopo-procaptcha/* ${{ github.workspace }}/release/trunk
shell: bash
30 changes: 30 additions & 0 deletions .github/actions/tests/clone-private-repository/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Clone Private Repository

inputs:
private_folder:
description: "Target folder the private repo should be extract to"
required: true
private_repo:
description: "Repo with paid plugin archives"
required: true
private_key:
description: "Private SSH key to access the private repository"
required: true

runs:
using: "composite"
steps:
- name: Clone Private Plugin Repository
run: |
mkdir -p ${{ inputs.private_folder }}
cd ${{ inputs.private_folder }}

# Setup SSH Key for Private Repo Access
mkdir -p ~/.ssh
echo "${{ inputs.private_key }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts

# Clone the Private Repository
git clone [email protected]:${{ inputs.private_repo }} .
shell: bash
43 changes: 43 additions & 0 deletions .github/actions/tests/install-e2e-packages/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Install E2E Packages

runs:
using: "composite"
steps:
# we need to install PHP 7.4 separately from php 8.2 in the initial-setup,
# cause WordPress is compatible with PHP 7.4
- name: Install PHP 7.4
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, mysqli, opcache

- name: Install Nginx
run: sudo apt-get update && sudo apt-get install -y nginx
shell: bash

- name: Install MySQL client
run: sudo apt-get update && sudo apt-get install -y mysql-client
shell: bash

# cypress dependencies https://docs.cypress.io/guides/getting-started/installing-cypress#Linux-Prerequisites
- name: Install cypress dependencies
run: sudo apt-get update && sudo apt-get install -y libgtk2.0-0t64 libgtk-3-0t64 libgbm-dev libnotify-dev libnss3 libxss1 libasound2t64 libxtst6 xauth xvfb
shell: bash

- name: Install Chrome
run: |
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable
shell: bash

# used in the tasks/install-wordpress-with-plugins.yml
- name: Install JSON parser
run: sudo apt-get update && sudo apt-get install -y jq
shell: bash

# used in the /tests.yml
- name: Install wait-on
run: npm install -g wait-on
shell: bash
47 changes: 47 additions & 0 deletions .github/actions/tests/install-wordpress-with-plugins/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Install WordPress with Plugins

inputs:
paid_plugins_dir:
description: "Folder with archives for the paid plugins"
required: true

runs:
using: "composite"
steps:
- name: Download and setup WordPress
run: |
cd ${{ github.workspace }}
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* ${{ github.workspace }}
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/wordpress/" wp-config.php
sed -i "s/username_here/root/" wp-config.php
sed -i "s/password_here/wordpress/" wp-config.php
sed -i "s/localhost/127.0.0.1/" wp-config.php
sed -i "s/define( 'WP_DEBUG', false );/define( 'WP_DEBUG', true );\ndefine( 'WP_DEBUG_DISPLAY', false );\ndefine( 'WP_DEBUG_LOG', true );error_reporting( E_ALL );/" wp-config.php
cp -r ${{ github.workspace }}/prosopo-procaptcha ${{ github.workspace }}/wp-content/plugins/
mkdir -p ${{ github.workspace }}/wp-content/mu-plugins
cp ${{ github.workspace }}/data-for-tests/mu-plugin.php ${{ github.workspace }}/wp-content/mu-plugins/mu-plugin.php
shell: bash

- name: Install WordPress plugins
run: |
cd ${{ github.workspace }}/tests/cypress/e2e/${{ matrix.cypress-target }}
plugins=$(cat ./installation-list.json | jq -r '.plugins[]')
for plugin in $plugins; do
echo "Installing $plugin plugin"

paid_plugin_path="${{ inputs.paid_plugins_dir }}/$plugin.zip"

if [[ -f "$paid_plugin_path" ]]; then
echo "Found paid plugin ZIP for $plugin in the paid plugins directory."
unzip "$paid_plugin_path" -d ${{ github.workspace }}/wp-content/plugins/
else
echo "No local ZIP for $plugin, downloading from WordPress repository."
curl -L -o "$plugin.zip" "https://downloads.wordpress.org/plugin/$plugin.latest-stable.zip"
unzip "$plugin.zip" -d ${{ github.workspace }}/wp-content/plugins/
rm "$plugin.zip"
fi
done
shell: bash
27 changes: 27 additions & 0 deletions .github/actions/tests/prepare-e2e-workflow/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Prepare E2E Workflow

runs:
using: "composite"
steps:
- name: Move website files to /var/www/procaptcha
run: sudo mv ${{ github.workspace }}/* /var/www/procaptcha
shell: bash

# it's necessary, as cypress was installed under the 'runner' user, so these folders should left.
- name: Back tests and tools folders
run: |
sudo mv /var/www/procaptcha/tests ${{ github.workspace }}
sudo mv /var/www/procaptcha/tools ${{ github.workspace }}
shell: bash

- name: Set ownership of website files to www-data
run: sudo chown -R www-data:www-data /var/www/procaptcha
shell: bash

- name: Wait for WordPress to start
run: npx wait-on http://procaptcha.local --timeout 10000
shell: bash

- name: Check domain resolution
run: curl -I http://procaptcha.local
shell: bash
46 changes: 46 additions & 0 deletions .github/actions/tests/setup-e2e-packages/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Setup E2E Packages

runs:
using: "composite"
steps:
# note when using act, it uses copy of your '/etc/hosts', so it's important to override it instead of appending
- name: Override /etc/hosts
run: echo "127.0.0.1 localhost procaptcha.local" | sudo tee /etc/hosts
shell: bash

- name: Configure Nginx
run: |
sudo bash -c 'cat > /etc/nginx/sites-available/default <<EOF
server {
listen 80;
server_name localhost procaptcha.local;

root /var/www/procaptcha;
index index.php index.html index.htm;

location / {
try_files \$uri \$uri/ /index.php?\$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF'
shell: bash

# it's necessary step, as www-data from nginx has no access to the /home/runner/work/* folder
- name: Create procaptcha web directory
run: sudo mkdir /var/www/procaptcha && sudo chown -R www-data:www-data /var/www/procaptcha
shell: bash

- name: Start Nginx
run: sudo service nginx start
shell: bash

- name: Start PHP-FPM
run: sudo service php7.4-fpm start
shell: bash
43 changes: 43 additions & 0 deletions .github/workflows/release-new-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release New Version

on:
push:
tags:
# 1.0.0
- '[0-9]+\.[0-9]+\.[0-9]+'

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Initial setup
uses: ./.github/actions/initial-setup

- name: Make sure SVN_USERNAME and SVN_PASSWORD are present
run: |
if [ -z "${{ secrets.SVN_USERNAME }}" ]; then
echo "Set the SVN_USERNAME secret"
exit 1
fi
if [ -z "${{ secrets.SVN_PASSWORD }}" ]; then
echo "Set the SVN_PASSWORD secret"
exit 1
fi

- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion

- name: SVN prepare commit
id: svn_commit_preparation
uses: ./.github/actions/release/svn-prepare-commit

- name: SVN make commit
uses: ./.github/actions/release/svn-make-commit
with:
username: ${{ secrets.SVN_USERNAME }}
password: ${{ secrets.SVN_PASSWORD }}
tag: ${{ steps.svn_commit_preparation.outputs.release_tag }}
Loading
Loading