Generate and Publish CSV #73
This file contains 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: Generate and Publish CSV | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
jobs: | |
generate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Update CSV | |
id: update | |
run: echo $(python vrps.py) > output.txt | |
- name: Commit and push changes | |
if: ${{ steps.update.outputs.result == 'CSV Generated' }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Update CSV" --allow-empty | |
git push | |
- name: Upload output | |
uses: actions/upload-artifact@v2 | |
with: | |
name: output | |
path: output.txt | |
publish: | |
needs: generate | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download output | |
uses: actions/download-artifact@v2 | |
with: | |
name: output | |
- name: Read output | |
id: output | |
run: | | |
OUTPUT=$(cat output.txt) | |
echo "::set-output name=result::$OUTPUT" | |
- name: Checkout code | |
if: ${{ steps.output.outputs.result == 'CSV Generated' }} | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Get the date | |
id: date | |
run: | | |
DATE=$(date -d "-1 day" +'%Y-%m-%d') | |
echo "::set-output name=date::$DATE" | |
- name: Set new tag | |
if: ${{ steps.output.outputs.result == 'CSV Generated' }} | |
id: newtag | |
run: | | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
IFS='_' read -ra PARTS <<< "$LATEST_TAG" | |
CURRENT_YEAR=$(date +"%Y") | |
if (( ${PARTS[0]} < CURRENT_YEAR )); then | |
NEW_NUMBER=1 | |
else | |
IFS='-' read -ra NUMBER_PARTS <<< "${PARTS[1]}" | |
NEW_NUMBER=$(( ${NUMBER_PARTS[0]} + 1 )) | |
fi | |
NEW_TAG="${CURRENT_YEAR}_${NEW_NUMBER}" | |
echo "::set-output name=tag::${NEW_TAG}" | |
- name: Gen release | |
if: ${{ steps.output.outputs.result == 'CSV Generated' }} | |
id: gen_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.newtag.outputs.tag }} | |
release_name: VRPS ${{ steps.date.outputs.date }} | |
body: 'Updated for new AIRAC cycle' | |
draft: false | |
prerelease: false | |
- name: Upload Release | |
if: ${{ steps.output.outputs.result == 'CSV Generated' }} | |
id: upload-release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
asset_name: vrps.csv | |
asset_content_type: text/csv | |
upload_url: ${{ steps.gen_release.outputs.upload_url }} | |
asset_path: ./vrps.csv | |