From 906e1faa66602f8e680553649752396cc3623faa Mon Sep 17 00:00:00 2001 From: Thumster Date: Thu, 14 Dec 2023 14:17:24 +0800 Subject: [PATCH] generate release catalog to purple-a11y-test repository --- .github/workflows/generate-release-catalog.sh | 38 +++++++++ .../workflows/generate-release-catalog.yml | 82 ++++++++++--------- 2 files changed, 81 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/generate-release-catalog.sh diff --git a/.github/workflows/generate-release-catalog.sh b/.github/workflows/generate-release-catalog.sh new file mode 100644 index 00000000..7faa8286 --- /dev/null +++ b/.github/workflows/generate-release-catalog.sh @@ -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 diff --git a/.github/workflows/generate-release-catalog.yml b/.github/workflows/generate-release-catalog.yml index cc0e4440..d16deb00 100644 --- a/.github/workflows/generate-release-catalog.yml +++ b/.github/workflows/generate-release-catalog.yml @@ -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 }} \ No newline at end of file