Skip to content

Commit 35358e8

Browse files
authored
Only checkout the commit for the latest release
1 parent 8b6d139 commit 35358e8

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

.github/workflows/build-and-deploy-javadoc.yml

+57-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ jobs:
99
build-and-deploy:
1010
runs-on: ubuntu-latest
1111

12+
env:
13+
REPO: "benfry/processing4"
14+
REMOTE_URL: "https://github.com/benfry/processing4.git"
15+
1216
steps:
1317
- name: Checkout gh-pages branch
1418
uses: actions/checkout@v3
@@ -23,30 +27,73 @@ jobs:
2327

2428
- name: Ensure Ant is installed
2529
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
2836
29-
- name: Clone the processing4 repository
37+
- name: Get the latest release tag and commit SHA
38+
id: get-commit-sha
3039
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
3263
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
3473
working-directory: processing4/build
3574
run: |
3675
ant doc
3776
3877
- name: Copy Javadoc to /docs directory
3978
run: |
4079
if [ -d "processing4/build/javadoc/core" ]; then
41-
cp -r processing4/build/javadoc/core docs/
80+
cp -r processing4/build/javadoc/core ../docs/
4281
fi
4382
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
4588
run: |
4689
git config --global user.name "GitHub Actions"
4790
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
5198
env:
5299
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)