1
- name : Train and Release Model
1
+ name : Model Training and Release
2
2
3
3
on :
4
4
push :
5
5
branches : [ main ]
6
+ tags : [ 'v*.*.*' ] # Trigger on version tags
6
7
workflow_dispatch :
7
8
8
9
env :
@@ -13,13 +14,15 @@ jobs:
13
14
train-and-release :
14
15
runs-on : ubuntu-latest
15
16
permissions :
16
- contents : write
17
+ contents : write # Required for creating releases
17
18
packages : write
18
19
actions : read
19
20
20
21
steps :
21
22
- name : Checkout repository
22
23
uses : actions/checkout@v4
24
+ with :
25
+ fetch-depth : 0 # Needed for tag detection
23
26
24
27
- name : Set up Python 3.9
25
28
uses : actions/setup-python@v4
56
59
57
60
- name : Verify artifacts
58
61
run : |
59
- echo "Generated artifacts in release/latest :"
62
+ echo "Generated artifacts:"
60
63
ls -lR ./$RELEASE_DIR/latest
61
64
62
65
REQUIRED_FILES=(
@@ -80,44 +83,66 @@ jobs:
80
83
exit 1
81
84
fi
82
85
83
- - name : Create release package
86
+ - name : Package release assets
84
87
run : |
85
- echo "Contents of release directory before packaging:"
86
- ls -lR ./$RELEASE_DIR
87
-
88
88
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
89
89
RELEASE_NAME="model_$TIMESTAMP"
90
90
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 .
93
93
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
95
97
96
- rm -rf ./$RELEASE_DIR/temp_package
97
-
98
- echo "Created package:"
98
+ echo "Release assets prepared:"
99
99
ls -l ./$RELEASE_DIR/*.tar.gz
100
100
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
108
114
109
115
- name : Create GitHub Release
110
- if : startsWith(github.ref, 'refs/tags/')
111
116
uses : softprops/action-gh-release@v1
112
117
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 }}"
114
120
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
122
138
env :
123
139
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