Last active
May 31, 2021 15:52
-
-
Save marlluslustosa/0f77d3d9927604141d1c299efdf25b87 to your computer and use it in GitHub Desktop.
Ranking featured posts
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: Ranking featured posts | |
on: | |
push: | |
branches: [ master ] | |
schedule: | |
# At 07:00 (every day) | |
- cron: '0 7 * * *' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo | |
- name: Create local changes | |
id: ranking | |
run: | | |
bash export_goat.sh ${{ secrets.TOKEN_GOAT }} ${{ secrets.API_URL_GOAT }} > export.txt | |
cp ranking_posts ranking_posts_old | |
bash edit_ranking.sh | |
#test - compare two files byte by byte | |
if cmp -s ranking_posts ranking_posts_old ; then | |
echo '::set-output name=NEWFILERANKING::false' | |
else | |
echo '::set-output name=NEWFILERANKING::true' | |
text="$(cat ranking_posts_name)" | |
echo "$text" | |
text="${text//'%'/'%25'}" | |
text="${text//$'\n'/'%0A'}" | |
text="${text//$'\r'/'%0D'}" | |
echo "$text" | |
echo "::set-output name=ranking_list_name::$text" | |
fi | |
rm -rf ranking_posts_old export.txt | |
- name: Commit files | |
id: commit | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add -A | |
git diff-index --quiet HEAD || git commit -m "edit ranking featured posts" | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
- name: SendGrid Action | |
uses: mmichailidis/[email protected] | |
with: | |
sendgrid-token: ${{ secrets.SENDGRID_API_KEY }} | |
mail: [email protected] #email de destino | |
#from sendgrid - https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html | |
from: [email protected] | |
subject: Artigos em destaque - Lulu space | |
text: | | |
${{ steps.ranking.outputs.ranking_list_name }} | |
#if files not equals then | |
if: steps.ranking.outputs.NEWFILERANKING == 'true' | |
- name: Notify telegram bot | |
uses: appleboy/telegram-action@master | |
with: | |
to: ${{ secrets.TELEGRAM_TO }} | |
token: ${{ secrets.TELEGRAM_TOKEN }} | |
message_file: ranking_posts_name #file with message about new ranking posts | |
if: steps.ranking.outputs.NEWFILERANKING == 'true' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment