Skip to content

Commit 2f5f0f9

Browse files
Merge pull request #12 from ahmed-n-abdeltwab/feature/make-modular
feat(ci): implement automated model releases with version tagging
2 parents 13b4bcb + 26e503b commit 2f5f0f9

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

.github/workflows/train_and_release.yml

+54-29
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
name: Train and Release Model
1+
name: Model Training and Release
22

33
on:
44
push:
55
branches: [ main ]
6+
tags: [ 'v*.*.*' ] # Trigger on version tags
67
workflow_dispatch:
78

89
env:
@@ -13,13 +14,15 @@ jobs:
1314
train-and-release:
1415
runs-on: ubuntu-latest
1516
permissions:
16-
contents: write
17+
contents: write # Required for creating releases
1718
packages: write
1819
actions: read
1920

2021
steps:
2122
- name: Checkout repository
2223
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # Needed for tag detection
2326

2427
- name: Set up Python 3.9
2528
uses: actions/setup-python@v4
@@ -56,7 +59,7 @@ jobs:
5659
5760
- name: Verify artifacts
5861
run: |
59-
echo "Generated artifacts in release/latest:"
62+
echo "Generated artifacts:"
6063
ls -lR ./$RELEASE_DIR/latest
6164
6265
REQUIRED_FILES=(
@@ -80,44 +83,66 @@ jobs:
8083
exit 1
8184
fi
8285
83-
- name: Create release package
86+
- name: Package release assets
8487
run: |
85-
echo "Contents of release directory before packaging:"
86-
ls -lR ./$RELEASE_DIR
87-
8888
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
8989
RELEASE_NAME="model_$TIMESTAMP"
9090
91-
mkdir -p ./$RELEASE_DIR/temp_package
92-
cp -r ./$RELEASE_DIR/latest/* ./$RELEASE_DIR/temp_package/
91+
# Create archive with all artifacts
92+
tar -czvf ./$RELEASE_DIR/$RELEASE_NAME.tar.gz -C ./$RELEASE_DIR/latest .
9393
94-
tar -czvf ./$RELEASE_DIR/$RELEASE_NAME.tar.gz -C ./$RELEASE_DIR/temp_package .
94+
# Create version file
95+
MODEL_VERSION=$(jq -r '.timestamp + "-" + .model_type' ./$RELEASE_DIR/latest/metadata.json)
96+
echo $MODEL_VERSION > ./$RELEASE_DIR/version.txt
9597
96-
rm -rf ./$RELEASE_DIR/temp_package
97-
98-
echo "Created package:"
98+
echo "Release assets prepared:"
9999
ls -l ./$RELEASE_DIR/*.tar.gz
100100
101-
- name: Upload artifact
102-
if: success()
103-
uses: actions/upload-artifact@v4
104-
with:
105-
name: model-release
106-
path: ${{ env.RELEASE_DIR }}/*.tar.gz
107-
if-no-files-found: error
101+
- name: Auto-tag release (on main branch)
102+
if: github.ref == 'refs/heads/main'
103+
id: autotag
104+
run: |
105+
# Get version from metadata
106+
VERSION=$(jq -r '.timestamp' ./$RELEASE_DIR/latest/metadata.json | cut -c1-10 | tr -d '-')
107+
TAG_NAME="v1.0.$VERSION"
108+
109+
# Create lightweight tag
110+
git tag $TAG_NAME
111+
git push origin $TAG_NAME
112+
113+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
108114
109115
- name: Create GitHub Release
110-
if: startsWith(github.ref, 'refs/tags/')
111116
uses: softprops/action-gh-release@v1
112117
with:
113-
name: "Model Release $(date +'%Y-%m-%d')"
118+
tag_name: ${{ github.ref_name || steps.autotag.outputs.tag_name }}
119+
name: "Model Release ${{ github.ref_name || steps.autotag.outputs.tag_name }}"
114120
body: |
115-
Automated model training results:
116-
- Model: $(jq -r '.model_type' ./$RELEASE_DIR/latest/metadata.json)
117-
- Timestamp: $(jq -r '.timestamp' ./$RELEASE_DIR/latest/metadata.json)
118-
- Metrics:
119-
Accuracy: $(jq -r '.metrics.accuracy' ./$RELEASE_DIR/latest/metrics.json)
120-
F1 Score: $(jq -r '.metrics.f1' ./$RELEASE_DIR/latest/metrics.json)
121-
files: ./$RELEASE_DIR/*.tar.gz
121+
## Model Details
122+
- **Type**: $(jq -r '.model_type' ./$RELEASE_DIR/latest/metadata.json)
123+
- **Training Date**: $(jq -r '.timestamp' ./$RELEASE_DIR/latest/metadata.json)
124+
125+
## Performance Metrics
126+
```json
127+
$(cat ./$RELEASE_DIR/latest/metrics.json)
128+
```
129+
130+
## Version Info
131+
$(cat ./$RELEASE_DIR/version.txt)
132+
files: |
133+
${{ env.RELEASE_DIR }}/*.tar.gz
134+
${{ env.RELEASE_DIR }}/latest/metadata.json
135+
${{ env.RELEASE_DIR }}/latest/metrics.json
136+
draft: false
137+
prerelease: false
122138
env:
123139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140+
141+
- name: Upload workflow artifact
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: model-release
145+
path: |
146+
${{ env.RELEASE_DIR }}/*.tar.gz
147+
${{ env.RELEASE_DIR }}/version.txt
148+
if-no-files-found: error

0 commit comments

Comments
 (0)