Repository navigation
96 lines (87 loc) · 4.07 KB
/
Copy pathweekly_csv_release.yml
File metadata and controls
96 lines (87 loc) · 4.07 KB
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
94
95
96
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
permissions:
contents: write
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
with:
python-version: "3.14"
# This job publishes releases, so don't restore a possibly poisoned cache.
enable-cache: false
- name: Install dependencies
run: uv sync --locked --no-dev
- name: Create CSV
run: uv run --no-sync 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@e31e87e03dd19038e411e38ae27cbad084a90661 # v2.3.3
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: |
export TZ="America/New_York"
DaySuffix() {
case `date +%-d` in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
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 "${TAG_NAME}" ./private/output/ocw_oer_export.csv -p -t "${RELEASE_TITLE}" -n "This release was created for CSV weekly output. Please get the CSV file from the Assets listed below." --target $GITHUB_SHA
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update 'Latest' Release
run: |
LATEST_RELEASE_NAME="latest"
# Checkout doesn't persist credentials, so delete the release and its tag
# through the API rather than with git push.
if gh release view $LATEST_RELEASE_NAME > /dev/null 2>&1
then
gh release delete $LATEST_RELEASE_NAME --yes --cleanup-tag
fi
# Remove a tag left behind without its release, or the new release would reuse it.
# git/ref/ matches exactly; git/refs/ would also match tags that merely start with the name.
if gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${LATEST_RELEASE_NAME}" > /dev/null 2>&1
then
gh api -X DELETE "repos/${GITHUB_REPOSITORY}/git/refs/tags/${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 --target $GITHUB_SHA
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}