-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (110 loc) · 5.05 KB
/
regenerate_tidalapi_module.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Regenerate TidalApi Code
on:
push:
env:
TARGET_BRANCH: michael/mainTesting
permissions:
contents: write
pull-requests: write
jobs:
openapi-code-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get link to released openapi-generator fork .jar
id: get_release
run: |
REPO_OWNER="tidal-music"
REPO_NAME="openapi-generator"
curl -s -H -v "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" > release_info.json
# Extract the download URL for the desired asset (example: 'my-asset.zip')
ASSET_URL=$(jq -r '.assets[] | select(.name == "openapi-generator-cli.jar") | .browser_download_url' release_info.json)
echo "::set-output name=asset_url::$ASSET_URL"
- name: Download generator binary
run: |
REPO_OWNER="organization"
REPO_NAME="another-repo"
ASSET_URL=${{ steps.get_release.outputs.asset_url }}
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/octet-stream" \
-o tidalapi/bin/openapi-generator-cli.jar \
"$ASSET_URL"
- name: Run the TidalAPI code generation
run: |
cd tidalapi
chmod +x ./bin/openapi-generator-cli.jar
python ./bin/generate-api-files.py ./bin/generate-api-config.json
git status
env:
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
- name: Check for changes
id: check_changes
env:
GENERATED_FOLDER_NAME: "tidalapi/src/main/kotlin/com/tidal/sdk/tidalapi/generated"
run: |
git add ./tidalapi
changes_in_generated=$(git status -s $GENERATED_FOLDER_NAME | sed 's/"//g')
echo "Changes in $GENERATED_FOLDER_NAME:"
echo "$changes_in_generated"
if [ -n "$changes_in_generated" ]; then
changes_detected="true"
# Count the number of changed files (lines in changes_in_generated)
changed_file_count=$(echo "$changes_in_generated" | wc -l)
else
changes_detected="false"
changed_file_count=0
fi
echo "Changes detected: $changes_detected"
echo "Number of changed files: $changed_file_count"
{
echo 'changed_files<<EOF'
echo "$changes_in_generated"
echo 'EOF'
} >> $GITHUB_OUTPUT
echo "changes_detected=$changes_detected" >> $GITHUB_OUTPUT
echo "changed_file_count=$changed_file_count" >> $GITHUB_OUTPUT
- name: Commit changes
id: commit_changes
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
git config user.email "svc-github-tidal-music-tools@block.xyz"
git config user.name "TIDAL Music Tools"
timestamp=$(date +"%Y-%m-%d-%H-%M-%S")
BRANCH_NAME="tidal-music-tools/Update-Tidal-Api-$timestamp"
git checkout -b $BRANCH_NAME
# Generate commit message with the number of changed files in the title and the list in the body
COMMIT_TITLE="Add ${{ steps.check_changes.outputs.changed_file_count }} files via GitHub Actions"
COMMIT_BODY="Changed files:\n${{ steps.check_changes.outputs.changed_files }}"
git add .
git commit -m "$COMMIT_TITLE"$'\n\n'"$COMMIT_BODY"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Push changes
if: steps.check_changes.outputs.changes_detected == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ steps.commit_changes.outputs.branch_name }}
run: |
git push --set-upstream origin "${{env.BRANCH_NAME}}"
- name: Create Pull Request via API
if: steps.check_changes.outputs.changes_detected == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGED_FILES: ${{ steps.check_changes.outputs.changed_files }}
CHANGED_FILE_COUNT: ${{ steps.check_changes.outputs.changed_file_count }}
BRANCH_NAME: ${{ steps.commit_changes.outputs.branch_name }}
run: |
PR_TITLE="Automatic Tidal API module update - ${{env.CHANGED_FILE_COUNT}} files changed"
PR_BODY="Changed files:\n\n${{ env.CHANGED_FILES }}"
PR_BODY=$(echo -e "$PR_BODY")
PR_DATA=$(jq -n --arg title "$PR_TITLE" \
--arg head "${{env.BRANCH_NAME}}" \
--arg base "${{ env.TARGET_BRANCH }}" \
--arg body "$PR_BODY" \
'{title: $title, head: $head, base: $base, body: $body}')
echo $PR_DATA
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "$PR_DATA" \
https://api.github.com/repos/${{ github.repository }}/pulls