Skip to content

Commit 1cdc909

Browse files
committed
Switch build cleanup to self-hosted
1 parent d484f96 commit 1cdc909

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

.github/workflows/auto_builds_cleanup.yml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@ on:
77
types: [ closed ]
88
branches-ignore: [ main ]
99

10+
env:
11+
builds-directory: ~/builds/athemes
12+
1013
jobs:
1114
cleaning:
1215
# The type of runner that the job will run on.
13-
runs-on: ubuntu-22.04
16+
runs-on: self-hosted
1417

1518
steps:
1619
# This action exposes GitHub environment variables to be used in subsequent steps.
1720
- name: GitHub Environment Variables Action
1821
uses: FranzDiebold/[email protected]
1922

20-
# This step installs the SSH key to allow the runner to authenticate with the staging server.
21-
- name: Install SSH Key
22-
uses: shimataro/ssh-key-action@v2
23-
with:
24-
key: ${{ secrets.WPFORMS_TEST_DOCKER_SSH_PRIVATE_KEY }}
25-
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
26-
2723
# This step sets a project name environment variable based on the repository name.
2824
# It takes the full repository name (e.g., "owner/repo"), extracts the repository name part,
2925
# converts it to lowercase, and saves it as PROJECT_NAME in the GitHub environment.
@@ -33,19 +29,10 @@ jobs:
3329
repo_short_name="${repo_full_name##*/}"
3430
echo "PROJECT_NAME=${repo_short_name,,}" >> $GITHUB_ENV
3531
36-
# This step sets up an SSH key to allow the runner to authenticate with the staging server.
37-
# It creates the .ssh directory, writes the private key from secrets, and sets the correct permissions.
38-
- name: Setup SSH key for hub.wpforms.com upload
39-
run: |
40-
mkdir -p ~/.ssh
41-
echo "${{ secrets.WPFORMS_TEST_DOCKER_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
42-
chmod 600 ~/.ssh/id_ed25519
43-
chmod 700 ~/.ssh
44-
45-
- name: Adding Known Hosts
46-
run: ssh-keyscan -p 18765 -H ${{ secrets.WPFORMS_STAGING_HOST }} >> ~/.ssh/known_hosts
32+
- name: Delete merged branch from local builds directory
33+
run: rm -r ${{ env.builds-directory }}/${{ env.PROJECT_NAME }}/${{ env.CI_REF_NAME_SLUG }}
4734

4835
# This step connects to the staging server via SSH and deletes the build directory
4936
# associated with the closed pull request's branch.
50-
- name: Delete builds from merged branch
37+
- name: Delete merged branch from hub.wpforms.com/builds
5138
run: ssh -p18765 staging@${{ secrets.WPFORMS_STAGING_HOST }} "cd /home/staging/shared/hub.wpforms.com/builds/athemes/${{ env.PROJECT_NAME }} && rm -rf ${{ env.CI_ACTION_REF_NAME_SLUG }}"

.github/workflows/auto_builds_cleanup_daily.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ name: Auto-builds Daily Cleanup
1010
schedule:
1111
- cron: '1 0 * * *' # Runs the workflow every day at 00:01.
1212

13+
env:
14+
builds-directory: ~/builds/athemes
15+
1316
jobs:
1417
cleaning:
1518
name: Delete builds for non existing branches
16-
runs-on: ubuntu-22.04
19+
runs-on: self-hosted
1720

1821
steps:
1922

@@ -25,13 +28,6 @@ jobs:
2528
- name: GitHub Environment Variables Action
2629
uses: FranzDiebold/[email protected]
2730

28-
# This step installs the SSH key to allow the runner to authenticate with the staging server.
29-
- name: Install SSH Key
30-
uses: shimataro/ssh-key-action@v2
31-
with:
32-
key: ${{ secrets.WPFORMS_TEST_DOCKER_SSH_PRIVATE_KEY }}
33-
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
34-
3531
# This step extracts the repository name from the full repository path and sets it as a PROJECT_NAME environment variable.
3632
# e.g. if the repository is aThemes/merchant, the project name will be "merchant".
3733
- name: Set Project Name
@@ -40,19 +36,6 @@ jobs:
4036
repo_short_name="${repo_full_name##*/}"
4137
echo "PROJECT_NAME=${repo_short_name,,}" >> $GITHUB_ENV
4238
43-
# This step sets up an SSH key to allow the workflow to connect to the staging server.
44-
# The private key is stored as a secret in the GitHub repository.
45-
- name: Setup SSH key for hub.wpforms.com upload
46-
run: |
47-
mkdir -p ~/.ssh
48-
echo "${{ secrets.WPFORMS_TEST_DOCKER_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
49-
chmod 600 ~/.ssh/id_ed25519
50-
chmod 700 ~/.ssh
51-
52-
# This step adds the known hosts to the SSH key.
53-
- name: Adding Known Hosts
54-
run: ssh-keyscan -p 18765 -H ${{ secrets.WPFORMS_STAGING_HOST }} >> ~/.ssh/known_hosts
55-
5639
# This step fetches the latest list of remote branches, formats the branch names, and saves them to a file named branches.txt.
5740
# The formatting removes the "origin/" prefix and replaces slashes and dots with hyphens.
5841
- name: Prepare list of branches
@@ -85,3 +68,18 @@ jobs:
8568
ssh -n -p18765 staging@${{ secrets.WPFORMS_STAGING_HOST }} "cd /home/staging/shared/hub.wpforms.com/builds/athemes/${{ env.PROJECT_NAME }} && rm -rf $dir"
8669
fi
8770
done < auto-builds.txt
71+
72+
# The list of auto-builds is saved to a file named auto-builds.txt.
73+
- name: Get list of local builds
74+
run: cd ${{ env.builds-directory }}/${{ env.PROJECT_NAME }} && ls > local-builds.txt
75+
76+
- name: Delete local builds if they're not in the list of branches
77+
run: |
78+
while read -r dir; do
79+
echo "Checking auto-build: $dir"
80+
if ! grep -q "$dir" branches.txt
81+
then
82+
echo "Deleting local-build: $dir"
83+
cd ${{ env.builds-directory }}/${{ env.PROJECT_NAME }} && rm -rf $dir"
84+
fi
85+
done < local-builds.txt

0 commit comments

Comments
 (0)