Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISCUSSION] Implement a Github Action/CI Job which does the line sorting in appfilter.xml automatically #1079

Open
peterge1998 opened this issue Mar 1, 2023 · 8 comments
Labels
discussion under discussion internally This issue or PR is being discussed in our private chats.

Comments

@peterge1998
Copy link
Contributor

About this discussion

Hey guys, I am tired of doing such simple and time-consuming tasks manually (see @Chefski's comment: #1077 (review)) and I bet you are tired of reminding people to sort their lines.
So let's combine our interests and set up an Action/CI Job to do the sorting automatically, when new lines get added to appfilter.xml.
I did the sorting with VS Code, which is able to sort all lines ascending. But to do that, I needed to select all lines below <!-- Lawnicons -->.

So let's rework the structure in the file and implement that fcking sorting to be done automatically! As a start, I could imagine a solution based on the sort appfilter.xml command.

@Chefski
Copy link
Member

Chefski commented Mar 1, 2023

As mentioned in my reply, we will try to automate this.

If you have suggestions as to how we can do this, just share it in here.

@Chefski Chefski added the under discussion internally This issue or PR is being discussed in our private chats. label Mar 1, 2023
@peterge1998
Copy link
Contributor Author

peterge1998 commented Mar 2, 2023

As mentioned in my reply, we will try to automate this.

If you have suggestions as to how we can do this, just share it in here.

After removing the comment lines temporarily, the task becomes very easy to do with sort from coreutils.
I just selected " as delimiter and select the fourth field (which is the name. I guess its better than sorting with drawable?) from appfilter.xml:

$ cat app/assets/appfilter.xml | sort -t '"' -k 4 | head
  <item component="ComponentInfo{dev.kdrag0n.android12ext/dev.kdrag0n.android12ext.ui.main.MainActivity}" drawable="a12_extensions" name="Android 12 Extensions"/>
  <item component="ComponentInfo{mattecarra.accapp/mattecarra.accapp.activities.MainActivity}" drawable="accubattery" name="AccA"/>
  <item component="ComponentInfo{com.digibites.accubattery/com.digibites.abatterysaver.BatterySaverActivity}" drawable="accubattery" name="AccuBattery"/>
  <item component="ComponentInfo{com.accuweather.android/com.accuweather.android.splashscreen.SplashActivity}" drawable="accuweather" name="AccuWeather"/>
  <item component="ComponentInfo{com.acronis.acronistrueimage/com.acronis.mobile.ui2.TheMainActivity}" drawable="acronis_mobile" name="Acronis Mobile"/>
  <item component="ComponentInfo{com.google.android.apps.accessibility.maui.actionblocks/com.google.android.apps.accessibility.maui.actionblocks.home.HomeActivity}" drawable="action_blocks" name="Action Blocks"/>
  <item component="ComponentInfo{de.actionbound/de.actionbound.MainActivity}" drawable="actionbound" name="Actionbound"/>
  <item component="ComponentInfo{org.adaway/org.adaway.AdAway}" drawable="adaway" name="AdAway"/>
  <item component="ComponentInfo{org.adaway/org.adaway.ui.BaseActivity}" drawable="adaway" name="AdAway"/>
  <item component="ComponentInfo{org.adaway/org.adaway.ui.home.HomeActivity}" drawable="adaway" name="AdAway"/>
$ cat app/assets/appfilter.xml | sort -t '"' -k 4 | tail
  <item component="ComponentInfo{com.zdf.android.mediathek/com.zdf.android.mediathek.ui.splash.SplashActivity}" drawable="zdfmediathek" name="ZDFmediathek"/>
  <item component="ComponentInfo{net.zedge.android/net.zedge.android.MainDefault}" drawable="zedge" name="Zedge"/>
  <item component="ComponentInfo{com.xiaomi.hm.health/cn.com.smartdevices.bracelet.activity.MainActivity}" drawable="zepp_life" name="Zepp Life"/>
  <item component="ComponentInfo{com.xiaomi.hm.health/cn.com.smartdevices.bracelet.activity.StartUpActivity}" drawable="zepp_life" name="Zepp Life"/>
  <item component="ComponentInfo{com.xiaomi.hm.health/com.xiaomi.hm.health.activity.StartUpActivity}" drawable="zepp_life" name="Zepp Life"/>
  <item component="ComponentInfo{com.zeptoconsumerapp/com.zeptoconsumerapp.MainActivity}" drawable="zepto" name="Zepto"/>
  <item component="ComponentInfo{com.zeus.app/rideatom.app.features.SecondActivity}" drawable="zeus" name="ZEUS Deutschland"/>
  <item component="ComponentInfo{com.application.zomato/com.application.zomato.activities.Splash}" drawable="zomoto" name="Zomoto"/>
  <item component="ComponentInfo{com.application.zomato/com.application.zomato.Splash}" drawable="zomoto" name="Zomoto"/>
  <item component="ComponentInfo{us.zoom.videomeetings/com.zipow.videobox.LauncherActivity}" drawable="zoom" name="Zoom"/>

@Chefski
Copy link
Member

Chefski commented Mar 3, 2023

So then comments are the only thing preventing this from being the solution?

@peterge1998
Copy link
Contributor Author

peterge1998 commented Mar 3, 2023

If I think correctly, yes. We can add this to the file, after the sorting is done:

<?xml version="1.0" encoding="UTF-8"?>
<resources>

and
</resources>
at the bottom. I still need to lookup the command on how to insert at the top (maybe with sed? -> https://stackoverflow.com/questions/49778741/add-a-new-line-of-text-at-the-top-of-a-file-in-bash-shell#49778797). The bottom line >> will do just fine. Then the comments need to disappear from the file. This doesnt matter anyway, because all Calendar lines will be next to each other :)

If you tell me that you consider switching to automated searching, I can prepare an example.

@Chefski
Copy link
Member

Chefski commented Mar 4, 2023

Sure. You can prepare an example

@peterge1998
Copy link
Contributor Author

peterge1998 commented Mar 5, 2023

Okay, it's rather simple. A script with just 4 lines does the job, if all comments and the heading line (<?xml version="1.0" encoding="UTF-8"?>\n\n<resources>\n) are removed from appfilter.xml.
First sort it by the fourth column, setting " as delimiter, and write it to appfilter_sorted.xml:
cat appfilter.xml | sort -t '"' -k 4 > appfilter_sorted.xml
Then write the first 3 lines with sed:
sed -i '1s/^/<?xml version="1.0" encoding="UTF-8"?>\n\n<resources>\n/' appfilter_sorted.xml
And finally append the last line via >>:
echo "</resources>" >> appfilter_sorted.xml
Now sth like mv appfilter_sorted.xml appfilter.xml and committing and pushing the file would do the job for the action.

$ cat appfilter_sorted.xml | head
<?xml version="1.0" encoding="UTF-8"?>

<resources>
  <item component="ComponentInfo{dev.kdrag0n.android12ext/dev.kdrag0n.android12ext.ui.main.MainActivity}" drawable="a12_extensions" name="Android 12 Extensions" />
  <item component="ComponentInfo{mattecarra.accapp/mattecarra.accapp.activities.MainActivity}" drawable="accubattery" name="AccA" />
  <item component="ComponentInfo{com.digibites.accubattery/com.digibites.abatterysaver.BatterySaverActivity}" drawable="accubattery" name="AccuBattery" />
  <item component="ComponentInfo{com.accuweather.android/com.accuweather.android.splashscreen.SplashActivity}" drawable="accuweather" name="AccuWeather" />
  <item component="ComponentInfo{com.acronis.acronistrueimage/com.acronis.mobile.ui2.TheMainActivity}" drawable="acronis_mobile" name="Acronis Mobile" />
  <item component="ComponentInfo{com.google.android.apps.accessibility.maui.actionblocks/com.google.android.apps.accessibility.maui.actionblocks.home.HomeActivity}" drawable="action_blocks" name="Action Blocks" />
  <item component="ComponentInfo{de.actionbound/de.actionbound.MainActivity}" drawable="actionbound" name="Actionbound" />
$ cat appfilter_sorted.xml | tail
  <item component="ComponentInfo{net.zedge.android/net.zedge.android.MainDefault}" drawable="zedge" name="Zedge" />
  <item component="ComponentInfo{com.xiaomi.hm.health/cn.com.smartdevices.bracelet.activity.MainActivity}" drawable="zepp_life" name="Zepp Life" />
  <item component="ComponentInfo{com.xiaomi.hm.health/cn.com.smartdevices.bracelet.activity.StartUpActivity}" drawable="zepp_life" name="Zepp Life" />
  <item component="ComponentInfo{com.xiaomi.hm.health/com.xiaomi.hm.health.activity.StartUpActivity}" drawable="zepp_life" name="Zepp Life" />
  <item component="ComponentInfo{com.zeptoconsumerapp/com.zeptoconsumerapp.MainActivity}" drawable="zepto" name="Zepto" />
  <item component="ComponentInfo{com.zeus.app/rideatom.app.features.SecondActivity}" drawable="zeus" name="ZEUS Deutschland" />
  <item component="ComponentInfo{com.application.zomato/com.application.zomato.activities.Splash}" drawable="zomoto" name="Zomoto" />
  <item component="ComponentInfo{com.application.zomato/com.application.zomato.Splash}" drawable="zomoto" name="Zomoto" />
  <item component="ComponentInfo{us.zoom.videomeetings/com.zipow.videobox.LauncherActivity}" drawable="zoom" name="Zoom" />
</resources>

@Chefski
Copy link
Member

Chefski commented Mar 5, 2023

Out of curiosity, would it be possible to let the numbers be sorted with numbers?

For example 1.1.1.1 would be with 2048 rather than OLX.

Also seeing that you definitely have more knowledge in this than me, you're free to work on the Github Action on this. Not forcing though just seems like you'd do it better

@peterge1998
Copy link
Contributor Author

peterge1998 commented Mar 7, 2023

As I already wrote in #1088, the command needs to be cat appfilter.xml | sort -t '"' -k 6 > appfilter_tmp.xml to sort the 6th field which is name instead of drawable.

As the commands, needed for this action, are prepared, can anyone help me with setting up the action itself?
I have knowledge how .gitlab-ci.yml works, but I haven't worked with .github/workflow/*.yml files for a long time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion under discussion internally This issue or PR is being discussed in our private chats.
Projects
Development

No branches or pull requests

2 participants