Skip to content

Commit

Permalink
generate release catalog to purple-a11y-test repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Thumster committed Dec 14, 2023
1 parent c0c82af commit 906e1fa
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 39 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/generate-release-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Fetch release data
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/GovTechSG/purple-hats-desktop/releases/latest")
ALL_RELEASES=$(curl -s "https://api.github.com/repos/GovTechSG/purple-hats-desktop/releases")

# Extract the latest release and pre-release tags
LATEST_RELEASE_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
LATEST_PRE_RELEASE_TAG=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease) | .tag_name] | first')

# Extract the latest release and pre-release notes
LATEST_RELEASE_NOTES=$(echo "$LATEST_RELEASE" | jq -r '.body' | jq -s -R -r @json)
LATEST_PRE_RELEASE_NOTES=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease)][0] | .body' | jq -s -R -r @json)

# Extract all release and pre-release tags as comma-separated strings
ALL_RELEASE_TAGS=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease | not) | .tag_name | "\"\(.)\""] | join(",")')
ALL_PRE_RELEASE_TAGS=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease) | .tag_name | "\"\(.)\""] | join(",")')

# Create the JSON file in the 'docs' folder
mkdir -p docs
echo "{
\"latestRelease\": \"$LATEST_RELEASE_TAG\",
\"latestPreRelease\": \"$LATEST_PRE_RELEASE_TAG\",
\"allReleaseTags\": [$ALL_RELEASE_TAGS],
\"allPreReleaseTags\": [$ALL_PRE_RELEASE_TAGS],
\"latestReleaseNotes\": $LATEST_RELEASE_NOTES,
\"latestPreReleaseNotes\": $LATEST_PRE_RELEASE_NOTES
}" > docs/latest-release.json

# Show generated JSON
cat docs/latest-release.json

# Commit JSON file
git config --local user.name "${GITHUB_ACTOR}"
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add docs/latest-release.json
git commit -m "Update latest-release.json"
git push
82 changes: 43 additions & 39 deletions .github/workflows/generate-release-catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,54 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout purple-hats repository
uses: actions/checkout@v3

- name: Copy scripts to parent directory
run: |
cp .github/workflows/generate-release-catalog.sh ${{runner.temp}}
- name: Check if file exists
run: |
if [ -f ${{runner.temp}}/generate-release-catalog.sh ]; then
echo "File exists."
else
echo "File does not exist."
fi
- name: Checkout docs branch
uses: actions/checkout@v3
with:
ref: 'docs'

- name: Get release data
- name: Check if file exists
run: |
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/GovTechSG/purple-hats-desktop/releases/latest")
ALL_RELEASES=$(curl -s "https://api.github.com/repos/GovTechSG/purple-hats-desktop/releases")
# Extract the latest release and pre-release tags
LATEST_RELEASE_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
LATEST_PRE_RELEASE_TAG=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease) | .tag_name] | first')
# Extract the latest release and pre-release notes
LATEST_RELEASE_NOTES=$(echo "$LATEST_RELEASE" | jq -r '.body' | jq -s -R -r @json)
LATEST_PRE_RELEASE_NOTES=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease)][0] | .body' | jq -s -R -r @json)
# Extract all release and pre-release tags as comma-separated strings
ALL_RELEASE_TAGS=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease | not) | .tag_name | "\"\(.)\""] | join(",")')
ALL_PRE_RELEASE_TAGS=$(echo "$ALL_RELEASES" | jq -r '[.[] | select(.prerelease) | .tag_name | "\"\(.)\""] | join(",")')
# Create the JSON file in the 'docs' folder
mkdir -p docs
echo "{
\"latestRelease\": \"$LATEST_RELEASE_TAG\",
\"latestPreRelease\": \"$LATEST_PRE_RELEASE_TAG\",
\"allReleaseTags\": [$ALL_RELEASE_TAGS],
\"allPreReleaseTags\": [$ALL_PRE_RELEASE_TAGS],
\"latestReleaseNotes\": $LATEST_RELEASE_NOTES,
\"latestPreReleaseNotes\": $LATEST_PRE_RELEASE_NOTES
}" > docs/latest-release.json
if [ -f ${{runner.temp}}/generate-release-catalog.sh ]; then
echo "File exists."
else
echo "File does not exist."
fi
- name: Execute script to generate release catalog json
run: bash ${{runner.temp}}/generate-release-catalog.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout to purple-a11y-test repository
uses: actions/checkout@v3
with:
repository: ${{ github.repository_owner }}/purple-a11y-test
token: ${{ secrets.GITHUB_TOKEN }}

- name: Show generated JSON
run: cat docs/latest-release.json

- name: Commit JSON file
- name: Check if file exists
run: |
git config --local user.name "${GITHUB_ACTOR}"
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add docs/latest-release.json
git commit -m "Update latest-release.json"
git push
if [ -f ${{runner.temp}}/generate-release-catalog.sh ]; then
echo "File exists."
else
echo "File does not exist."
fi
- name: Execute script to generate release catalog json
run: bash ${{runner.temp}}/generate-release-catalog.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 906e1fa

Please sign in to comment.