-
Notifications
You must be signed in to change notification settings - Fork 2
93 lines (82 loc) · 3.38 KB
/
weekly_csv_release.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
name: Weekly CSV File Generation and Release
on:
push:
branches:
- main
schedule:
- cron: '0 10 * * 1' # Every Monday at 10AM
jobs:
generate_and_release_csv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "poetry"
- name: Set up Poetry Path
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: poetry install --no-interaction
- name: Create CSV
run: poetry run python -m ocw_oer_export.cli --create_csv --output_path="./private/output/ocw_oer_export.csv"
- name: Slack Notification
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#870000'
SLACK_MESSAGE: 'Error in creating CSV file. Please refer to the Actions URL to see logs.'
SLACK_MSG_AUTHOR: 'mitodl/ocw_oer_export'
- name: Generate Version Number
run: |
git fetch --tags
LATEST_TAG=$(git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-csv$' | sort -V | tail -n1)
# If no tags exist, start with v1.0.0-csv
if [ -z "$LATEST_TAG" ]
then
LATEST_TAG="v1.0.0-csv"
fi
BASE_TAG=${LATEST_TAG#v} # Remove the leading 'v'
BASE_TAG=${BASE_TAG%-csv} # Remove the trailing '-csv'
IFS='.' read -a TAG_PARTS <<< "$BASE_TAG"
TAG_PARTS[2]=$((TAG_PARTS[2]+1)) # Increment the patch number
NEW_TAG="v${TAG_PARTS[0]}.${TAG_PARTS[1]}.${TAG_PARTS[2]}-csv"
echo "TAG_NAME=$NEW_TAG" >> $GITHUB_ENV
- name: Format Release Date for Release Title
run: |
DaySuffix() {
case `date +%d` in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
TZ="US/Eastern"
TODAY=$(date +"%A, %B %-d"$(DaySuffix)", %Y")
echo "RELEASE_TITLE=${TODAY}" >> $GITHUB_ENV
- name: Create Release with Timestamp
run:
|
echo "Creating release: $TAG_NAME"
gh release create "${{ env.TAG_NAME }}" ./private/output/ocw_oer_export.csv -p -t "${{ env.RELEASE_TITLE }}" -n "This release was created for CSV weekly output. Please get the CSV file from the Assets listed below."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update 'Latest' Release
run: |
LATEST_RELEASE_NAME="latest"
if gh release view $LATEST_RELEASE_NAME
then
gh release delete $LATEST_RELEASE_NAME
fi
gh release create $LATEST_RELEASE_NAME ./private/output/ocw_oer_export.csv -t "Latest Release" -n "This release was created for CSV weekly output. This release contains the most recent CSV. Please get the CSV file from the Assets listed below." --latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}