Skip to content

Commit

Permalink
Add CI for building and releasing index files
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Oct 23, 2024
1 parent 7eabb82 commit aa79777
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/release-tag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
34 changes: 34 additions & 0 deletions .github/scripts/increment-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# File containing the version
TAG_FILE=".github/release-tag.txt"

# Read the current version from the file
if [ ! -f "$TAG_FILE" ]; then
echo "File with tag does not exist."
exit 1
fi

# Read the version from the file
read -r current_version < "$TAG_FILE"

# Break the version number into its components
IFS='.' read -r major minor patch <<< "$current_version"

# Ensure that the version number is valid
if ! [[ $major =~ ^[0-9]+$ && $minor =~ ^[0-9]+$ && $patch =~ ^[0-9]+$ ]]; then
echo "Error: Version number '$current_version' is not in a valid MAJOR.MINOR.PATCH format."
exit 1
fi

# Increment the patch version
patch=$((patch + 1))

# Assemble the new version number
new_version="${major}.${minor}.${patch}"

# Write the new version back to the file
echo "$new_version" > "$TAG_FILE"

# Return the new version
echo "$new_version"
33 changes: 33 additions & 0 deletions .github/scripts/swap-index-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Check for proper number of command line args.
if [ "$#" -ne 2 ]; then
echo "Usage: $0 path_to_json.xz new_url"
exit 1
fi

# Assign command line args to variables
input_file="$1"
new_url="$2"
temp_json="temp.json"

# Decompress the .xz file into a temporary JSON file
xz -d -k -c "${input_file}" > "${temp_json}"

# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq could not be found, please install jq to use this script."
exit 1
fi

# Update the URL field using jq
jq --arg new_url "$new_url" '.entries[0].url = $new_url' "${temp_json}" > "${temp_json}.tmp" && mv "${temp_json}.tmp" "${temp_json}"

# Compress the modified JSON file back into the .xz format
xz -z -c "${temp_json}" > "${input_file}"

# Remove the temporary JSON file
rm "${temp_json}"

echo "The url field has been updated to $new_url and the file ${input_file} is modified"
16 changes: 12 additions & 4 deletions .github/workflows/install-index-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
release:
needs: indexing
runs-on: ubuntu-latest
env:
TAG=($.github/increment-version.sh)
RELEASE_URL="https://github.com/${GITHUB_REPOSITORY}/releases/$TAG"

steps:
- name: Download Artifacts
Expand All @@ -54,18 +57,23 @@ jobs:
- name: IJ check indexes
run: ls -lhR indexing-results

- name: Swap data url in index.json.xz
run: |
PATH_TO_INDEX_FILE=(indexing-results/data/project/multi-jar/*.ijx.xz)
.github/scripts/swap-index-url.sh $PATH_TO_INDEX_FILE "$RELEASE_URL/$(basename "$PATH_TO_INDEX_FILE")"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 1.0.0
tag_name: $TAG
draft: true
prerelease: false
files: |
indexing-results/project/list.json.xz
indexing-results/project/multi-jar/index.json.xz
indexing-results/data/project/multi-jar/${{ github.sha }}/*.ijx.xz
indexing-results/data/project/multi-jar/${{ github.sha }}/*.metadata.json
indexing-results/data/project/multi-jar/${{ github.sha }}/*.sha256
indexing-results/data/project/multi-jar/*.ijx.xz
indexing-results/data/project/multi-jar/*.metadata.json
indexing-results/data/project/multi-jar/*.sha256

0 comments on commit aa79777

Please sign in to comment.