@@ -10,10 +10,13 @@ name: Auto-builds Daily Cleanup
10
10
schedule :
11
11
- cron : ' 1 0 * * *' # Runs the workflow every day at 00:01.
12
12
13
+ env :
14
+ builds-directory : ~/builds/athemes
15
+
13
16
jobs :
14
17
cleaning :
15
18
name : Delete builds for non existing branches
16
- runs-on : ubuntu-22.04
19
+ runs-on : self-hosted
17
20
18
21
steps :
19
22
25
28
- name : GitHub Environment Variables Action
26
29
uses :
FranzDiebold/[email protected]
27
30
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
-
35
31
# This step extracts the repository name from the full repository path and sets it as a PROJECT_NAME environment variable.
36
32
# e.g. if the repository is aThemes/merchant, the project name will be "merchant".
37
33
- name : Set Project Name
40
36
repo_short_name="${repo_full_name##*/}"
41
37
echo "PROJECT_NAME=${repo_short_name,,}" >> $GITHUB_ENV
42
38
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
-
56
39
# This step fetches the latest list of remote branches, formats the branch names, and saves them to a file named branches.txt.
57
40
# The formatting removes the "origin/" prefix and replaces slashes and dots with hyphens.
58
41
- name : Prepare list of branches
85
68
ssh -n -p18765 staging@${{ secrets.WPFORMS_STAGING_HOST }} "cd /home/staging/shared/hub.wpforms.com/builds/athemes/${{ env.PROJECT_NAME }} && rm -rf $dir"
86
69
fi
87
70
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