-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (164 loc) · 5.53 KB
/
Copy pathmain.yml
File metadata and controls
171 lines (164 loc) · 5.53 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allows manual triggering
permissions:
contents: write # Grant write permissions for creating releases and tags
pull-requests: write # Needed for some release actions, good practice
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Echo Test Job Start
run: echo "Starting Test Job on ${{ matrix.os }}"
- name: List files in working directory (Test Job)
run: ls -la
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install PyInstaller setuptools wheel
- name: Run tests
run: python -m unittest discover tests
build:
needs: test
runs-on: ${{ matrix.os }}
if: ${{ always() }} # Run even if 'test' job fails
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Echo Build Job Start
run: echo "Starting Build Job on ${{ matrix.os }}"
- name: List files in working directory (Build Job)
run: ls -la
- name: Set up Python
uses: actions:setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install PyInstaller setuptools wheel
- name: Build executable
run: pyinstaller --onefile --name pdfcli pdfcli/main.py
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: pdfcli-${{ matrix.os }}
path: dist/pdfcli*
create_tag:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && success()
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tag creation
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Get version from setup.py
id: get_version
run: |
VERSION=$(python -c "
import setuptools
import os
version = None
with open('setup.py', 'r') as f:
for line in f:
if 'version=' in line:
version = line.split('version=')[1].strip().strip("\',\").strip('"')
break
if version:
print(f\"VERSION={version}\")
else:
print(\"Error: Version not found in setup.py\")
exit(1)
")
echo "Extracted Version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag already exists
id: check_tag
run: |
TAG_NAME="v${{ steps.get_version.outputs.VERSION }}"
if git rev-parse $TAG_NAME >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists. Skipping tag creation."
echo "tag_exists=true" >> $GITHUB_OUTPUT
else:
echo "Tag $TAG_NAME does not exist. Proceeding with tag creation."
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
TAG_NAME="v${{ steps.get_version.outputs.VERSION }}"
echo "Attempting to create and push tag: $TAG_NAME"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag $TAG_NAME
git push origin $TAG_NAME
echo "Tag $TAG_NAME pushed successfully."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Ensure token is available for pushing tags
release:
needs: create_tag # Ensure this job runs after create_tag
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && success() # Only release if build succeeded AND a tag was pushed
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset (Windows)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/pdfcli-windows-latest/pdfcli.exe
asset_name: pdfcli-windows.exe
asset_content_type: application/octet-stream
- name: Upload Release Asset (Linux)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/pdfcli-ubuntu-latest/pdfcli
asset_name: pdfcli-linux
asset_content_type: application/octet-stream
- name: Upload Release Asset (macOS)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/pdfcli-macos-latest/pdfcli
asset_name: pdfcli-macos
asset_content_type: application/octet-stream