9
9
build-and-deploy :
10
10
runs-on : ubuntu-latest
11
11
12
+ env :
13
+ REPO : " benfry/processing4"
14
+ REMOTE_URL : " https://github.com/benfry/processing4.git"
15
+
12
16
steps :
13
17
- name : Checkout gh-pages branch
14
18
uses : actions/checkout@v3
@@ -23,30 +27,73 @@ jobs:
23
27
24
28
- name : Ensure Ant is installed
25
29
run : |
26
- sudo apt-get update
27
- sudo apt-get install -y ant
30
+ if ! command -v ant &> /dev/null; then
31
+ echo "Ant not found, installing..."
32
+ sudo apt-get update && sudo apt-get install -y ant
33
+ else
34
+ echo "Ant is already installed"
35
+ fi
28
36
29
- - name : Clone the processing4 repository
37
+ - name : Get the latest release tag and commit SHA
38
+ id : get-commit-sha
30
39
run : |
31
- git clone --depth 1 https://github.com/processing/processing4.git
40
+ # Step 1: Get the latest release tag
41
+ latest_tag=$(curl --silent "https://api.github.com/repos/${{ env.REPO }}/releases/latest" | jq -r .tag_name)
42
+ if [ -z "$latest_tag" ]; then
43
+ echo "Failed to retrieve the latest tag."
44
+ exit 1
45
+ fi
46
+ echo "Latest tag: $latest_tag"
47
+
48
+ # Step 2: Get the SHA associated with the tag
49
+ response=$(curl --silent "https://api.github.com/repos/${{ env.REPO }}/git/ref/tags/$latest_tag")
50
+ type=$(echo "$response" | jq -r '.object.type')
51
+ tag_sha=$(echo "$response" | jq -r '.object.sha')
52
+
53
+ # Step 3: Check if the tag points directly to a commit
54
+ if [ "$type" == "commit" ]; then
55
+ commit_sha="$tag_sha"
56
+ else
57
+ # If the tag points to an annotated tag, retrieve the commit SHA
58
+ commit_sha=$(curl --silent "https://api.github.com/repos/${{ env.REPO }}/git/tags/$tag_sha" | jq -r '.object.sha')
59
+ fi
60
+
61
+ echo "Commit SHA: $commit_sha"
62
+ echo "commit_sha=$commit_sha" >> $GITHUB_ENV
32
63
33
- - name : Generate Javadoc
64
+ - name : Fetch and checkout the specific commit
65
+ run : |
66
+ git init processing4
67
+ cd processing4
68
+ git remote add origin ${{ env.REMOTE_URL }}
69
+ git fetch --depth 1 origin ${{ env.commit_sha }}
70
+ git checkout ${{ env.commit_sha }}
71
+
72
+ - name : Generate Javadocs
34
73
working-directory : processing4/build
35
74
run : |
36
75
ant doc
37
76
38
77
- name : Copy Javadoc to /docs directory
39
78
run : |
40
79
if [ -d "processing4/build/javadoc/core" ]; then
41
- cp -r processing4/build/javadoc/core docs/
80
+ cp -r processing4/build/javadoc/core ../ docs/
42
81
fi
43
82
44
- - name : Commit and Push changes to gh-pages
83
+ - name : Clean up the processing4 directory
84
+ run : |
85
+ rm -rf processing4/
86
+
87
+ - name : Commit and Push changes to gh-pages if any changes exist
45
88
run : |
46
89
git config --global user.name "GitHub Actions"
47
90
git config --global user.email "[email protected] "
48
- git add docs/
49
- git commit -m "Update Javadocs"
50
- git push https://[email protected] /processing/processing4-javadocs.git HEAD:gh-pages
91
+ if [ -n "$(git status --porcelain docs/)" ]; then
92
+ git add docs/
93
+ git commit -m "Update Javadocs"
94
+ git push https://[email protected] /SableRaf/processing-javadoc-test.git HEAD:gh-pages
95
+ else
96
+ echo "No changes to commit."
97
+ fi
51
98
env :
52
99
PAT_TOKEN : ${{ secrets.PAT_TOKEN }}
0 commit comments