Skip to content

Commit 9c4ab9d

Browse files
authored
Update CI workflow (#22)
* Update CI workflow to create a full release with versioning based on article count * Refactor CI workflow to improve build and release process, including artifact uploads and versioning based on article count * use latest artifact actions * use latest checkout action and adjust release title format * Remove PDF file handling from CI workflow for artifact uploads
1 parent 6b7c3d0 commit 9c4ab9d

File tree

1 file changed

+65
-18
lines changed

1 file changed

+65
-18
lines changed

.github/workflows/ci.yml

+65-18
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,93 @@
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
26

37
on:
48
push:
59
branches: [main]
610
pull_request:
711
branches: [main]
812
schedule:
9-
- cron: "0 0 * * *" # Run every day at midnight UTC
13+
- cron: "0 0 * * *"
1014
workflow_dispatch:
1115

1216
jobs:
13-
check_and_build:
17+
build:
1418
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+
1623
steps:
17-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v4
1825
with:
19-
fetch-depth: 2 # To be able to get the changes
26+
fetch-depth: 2
2027

2128
- name: Check for file changes
2229
id: check_files
2330
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
2532
echo "changes_detected=true" >> $GITHUB_OUTPUT
2633
else
27-
echo "changes_detected=false" >> $GITHUB_OUTPUT
34+
echo "changes_detected=true" >> $GITHUB_OUTPUT # Always build for now
2835
fi
2936
30-
- name: Run build if changes detected
31-
if: steps.check_files.outputs.changes_detected == 'true'
37+
- name: Build
3238
run: |
3339
make all
3440
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
3785
uses: marvinpinto/action-automatic-releases@latest
3886
with:
3987
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 }}"
4391
files: |
44-
*.epub
45-
*.pdf
46-
*.csv
92+
dist/*.epub
93+
dist/essays.csv

0 commit comments

Comments
 (0)