Before asking for review on BTCMAP ADMIN check this #289
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Add comment to issue | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| jobs: | |
| add-issue-comment: | |
| environment: main | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: 🐍 Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| cache: 'pip' | |
| - name: 📦 Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Set dynamic variable | |
| run: echo -e "${{ github.event.issue.body }}" | awk '/NOTREMOVETHISPLEASEV1/{flag=1; next} flag' > issueData.json && DATA_SIZE=$(wc -c < issueData.json) && echo "DATA_SIZE=$DATA_SIZE" >> $GITHUB_ENV | |
| - name: mount data | |
| if: ${{ env.DATA_SIZE > 0 }} | |
| run: | | |
| OSM_ID=$(jq '.OSM_ID' issueData.json) | |
| GEO_JSON=$(curl "https://polygons.openstreetmap.fr/get_geojson.py?id=$OSM_ID¶ms=0.001-0.005-0.005") | |
| npm install -g mapshaper && curl "https://nominatim.openstreetmap.org/lookup?osm_ids=R$OSM_ID&format=json&polygon_geojson=" | jq '.[0].geojson' > input.json | |
| GEO_JSON2=$(mapshaper input.json -simplify 3% -o output.json && cat output.json | jq '.geometries[0]' -c) | |
| echo $GEO_JSON2 > boundaries.geojson | |
| python3 calculatePopulation.py | |
| URL_ALIAS=$(jq -r '.NAME' issueData.json | iconv -f UTF-8 -t ASCII//TRANSLIT | tr -dc '[:alnum:][:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g') | |
| bash writeOnComment.sh $(echo $GEO_JSON | jq '.coordinates[0][0] | length') "OSM fr polygons:" "" | |
| bash writeOnComment.sh "$GEO_JSON" "" "geojson" | |
| bash writeOnComment.sh $(echo $GEO_JSON2 | jq '.coordinates[0] | length') "Mapshaper polygons:" "" | |
| bash writeOnComment.sh "$GEO_JSON2" "" "geojson" | |
| bash writeOnComment.sh "$(jq -r '.AREA_TYPE' issueData.json)" "Area type:" "" | |
| bash writeOnComment.sh "$(jq -r '.CONTINENT' issueData.json)" "Continent:" "" | |
| bash writeOnComment.sh "$(jq -r '.ICON' issueData.json)" "Icon:" "" | |
| bash writeOnComment.sh "$(jq -r '.NAME' issueData.json)" "Name:" "" | |
| bash writeOnComment.sh "$(cat population_count.txt)" "Population:" "" | |
| bash writeOnComment.sh "$(cat populationDate.txt)" "Population Date:" "" | |
| bash writeOnComment.sh "$URL_ALIAS" "Url Alias:" "" | |
| bash writeOnComment.sh "$(jq -r '.LIGHTNING_TIPS' issueData.json)" "Lightning Tips:" "" | |
| jq '.CONTACT[]' -r issueData.json | while read -r contactItem; | |
| do | |
| bash writeOnComment.sh "$contactItem" "Contact:" "" | |
| done | |
| bash writeOnComment.sh "$(jq -r '.DESCRIPTION' issueData.json)" "Description:" "" | |
| bash writeOnComment.sh "$(jq -r '.ORGANIZATION' issueData.json)" "Organization:" "" | |
| bash writeOnComment.sh "https://btcmap.org/community/$URL_ALIAS" "Community link:" "" | |
| bash writeOnComment.sh "[Community](https://btcmap.org/community/$URL_ALIAS)" "Community link md:" "" | |
| - name: Set dynamic variable V2 | |
| run: echo -e "${{ github.event.issue.body }}" | awk '/NOTREMOVETHISPLEASEV2/{flag=1; next} flag' > issueData.json && DATA_SIZE=$(wc -c < issueData.json) && echo "DATA_SIZE=$DATA_SIZE" >> $GITHUB_ENV | |
| - name: mount data V2 | |
| if: ${{ env.DATA_SIZE > 0 }} | |
| run: | | |
| OSM_ID=$(jq '.OSM_ID' issueData.json) | |
| GEO_JSON=$(curl "https://polygons.openstreetmap.fr/get_geojson.py?id=$OSM_ID¶ms=0.001-0.005-0.005") | |
| ISSUE_ID=$(jq -r '.ISSUE_ID' issueData.json) | |
| npm install -g mapshaper && curl "https://nominatim.openstreetmap.org/lookup?osm_ids=R$OSM_ID&format=json&polygon_geojson=" | jq '.[0].geojson' > input.json | |
| bash getIssueData.sh ${{ vars.GIT_URL }} ${{ vars.REPO_OWNER }}/${{ vars.REPO_NAME }} $ISSUE_ID > extIssueData.json | |
| GEO_JSON2=$(mapshaper input.json -simplify 3% -o output.json && cat output.json | jq '.geometries[0]' -c) | |
| URL_ALIAS=$(jq -r '.NAME' extIssueData.json | iconv -f UTF-8 -t ASCII//TRANSLIT | tr -dc '[:alnum:][:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g') | |
| echo $GEO_JSON2 > boundaries.geojson | |
| python3 calculatePopulation.py | |
| bash writeOnComment.sh $(echo $GEO_JSON | jq '.coordinates[0][0] | length') "OSM fr polygons:" "" | |
| bash writeOnComment.sh "$GEO_JSON" "" "geojson" | |
| bash writeOnComment.sh $(echo $GEO_JSON2 | jq '.coordinates[0] | length') "Mapshaper polygons:" "" | |
| bash writeOnComment.sh "$GEO_JSON2" "" "geojson" | |
| bash writeOnComment.sh "$(jq -r '.AREA_TYPE' issueData.json)" "Area type:" "" | |
| bash writeOnComment.sh "$(jq -r '.CONTINENT' issueData.json)" "Continent:" "" | |
| bash writeOnComment.sh "$(jq -r '.ICON' extIssueData.json)" "Icon:" "" | |
| bash writeOnComment.sh "$(jq -r '.NAME' extIssueData.json)" "Name:" "" | |
| bash writeOnComment.sh "$(cat population_count.txt)" "Population:" "" | |
| bash writeOnComment.sh "$(cat populationDate.txt)" "Population Date:" "" | |
| bash writeOnComment.sh "$URL_ALIAS" "Url Alias:" "" | |
| jq '.CONTACT[]' -r extIssueData.json | while read -r contactItem; | |
| do | |
| bash writeOnComment.sh "$contactItem" "Contact:" "" | |
| done | |
| bash writeOnComment.sh "$(jq -r '.DESCRIPTION' extIssueData.json)" "Description:" "" | |
| bash writeOnComment.sh "$(jq -r '.ORGANIZATION' issueData.json)" "Organization:" "" | |
| bash writeOnComment.sh "https://btcmap.org/community/$URL_ALIAS" "Community link:" "" | |
| bash writeOnComment.sh "[Community](https://btcmap.org/community/$URL_ALIAS)" "Community link md:" "" | |
| - name: Read file contents | |
| id: read_file | |
| uses: andstor/file-reader-action@v1 | |
| with: | |
| path: "comment.md" | |
| - name: Create or update issue comment | |
| uses: peter-evans/create-or-update-comment@v5 | |
| if: ${{ env.DATA_SIZE > 0 }} | |
| with: | |
| issue-number: ${{ github.event.issue.number }} | |
| body: ${{ steps.read_file.outputs.contents }} |