1
- name : " Pre Release on File Change"
1
+ name : " Build and Release"
2
+
3
+ permissions :
4
+ contents : write # Needed for creating releases
5
+ pull-requests : read
2
6
3
7
on :
4
8
push :
5
9
branches : [main]
6
10
pull_request :
7
11
branches : [main]
8
12
schedule :
9
- - cron : " 0 0 * * *" # Run every day at midnight UTC
13
+ - cron : " 0 0 * * *"
10
14
workflow_dispatch :
11
15
12
16
jobs :
13
- check_and_build :
17
+ build :
14
18
runs-on : ubuntu-latest
15
-
19
+ outputs :
20
+ changes_detected : ${{ steps.check_files.outputs.changes_detected }}
21
+ num_articles : ${{ steps.count_articles.outputs.num_articles }}
22
+
16
23
steps :
17
- - uses : actions/checkout@v2
24
+ - uses : actions/checkout@v4
18
25
with :
19
- fetch-depth : 2 # To be able to get the changes
26
+ fetch-depth : 2
20
27
21
28
- name : Check for file changes
22
29
id : check_files
23
30
run : |
24
- if git diff --name-only HEAD^ HEAD | grep -E '\.(epub|pdf| csv)$'; then
31
+ if git diff --name-only HEAD^ HEAD | grep -E '\.(epub|csv)$'; then
25
32
echo "changes_detected=true" >> $GITHUB_OUTPUT
26
33
else
27
- echo "changes_detected=false " >> $GITHUB_OUTPUT
34
+ echo "changes_detected=true " >> $GITHUB_OUTPUT # Always build for now
28
35
fi
29
36
30
- - name : Run build if changes detected
31
- if : steps.check_files.outputs.changes_detected == 'true'
37
+ - name : Build
32
38
run : |
33
39
make all
34
40
35
- - name : Create release if changes detected
36
- if : steps.check_files.outputs.changes_detected == 'true'
41
+ - name : Count number of articles
42
+ id : count_articles
43
+ run : |
44
+ if [ -f "essays.csv" ]; then
45
+ NUM_ARTICLES=$(( $(wc -l < essays.csv) - 1 ))
46
+ NUM_ARTICLES=$(( NUM_ARTICLES < 0 ? 0 : NUM_ARTICLES ))
47
+ echo "num_articles=$NUM_ARTICLES" >> $GITHUB_OUTPUT
48
+ else
49
+ echo "num_articles=0" >> $GITHUB_OUTPUT
50
+ fi
51
+
52
+ - name : Upload artifacts
53
+ uses : actions/upload-artifact@v4
54
+ with :
55
+ name : build-artifacts
56
+ path : |
57
+ dist/
58
+ *.epub
59
+ essays.csv
60
+ retention-days : 30
61
+ if-no-files-found : error
62
+
63
+ release :
64
+ needs : build
65
+ runs-on : ubuntu-latest
66
+ if : needs.build.outputs.changes_detected == 'true'
67
+
68
+ steps :
69
+ - name : Download artifacts
70
+ uses : actions/download-artifact@v4
71
+ with :
72
+ name : build-artifacts
73
+ path : dist
74
+
75
+ - name : Generate version string
76
+ id : generate_version
77
+ working-directory : dist
78
+ run : |
79
+ DATE=$(date +%Y-%m-%d)
80
+ VERSION="${DATE}_${{ needs.build.outputs.num_articles }}"
81
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
82
+ echo "RELEASE_TITLE=$DATE, ${{ needs.build.outputs.num_articles }} essays" >> $GITHUB_ENV
83
+
84
+ - name : Create release
37
85
uses : marvinpinto/action-automatic-releases@latest
38
86
with :
39
87
repo_token : " ${{ secrets.GITHUB_TOKEN }}"
40
- automatic_release_tag : " latest "
41
- prerelease : true
42
- title : " Paul Graham Essays "
88
+ automatic_release_tag : " ${{ env.VERSION }} "
89
+ prerelease : false
90
+ title : " ${{ env.RELEASE_TITLE }} "
43
91
files : |
44
- *.epub
45
- *.pdf
46
- *.csv
92
+ dist/*.epub
93
+ dist/essays.csv
0 commit comments