-
Notifications
You must be signed in to change notification settings - Fork 5
144 lines (123 loc) · 4.59 KB
/
zip-on-pr.yml
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
name: Create Release Zip
on:
push:
branches:
- main
workflow_dispatch: # Allow manual triggering
jobs:
create-zip:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history to get merge commit info
- name: Get branch name
id: vars
run: |
if [[ ${{ github.event_name }} == 'push' ]]; then
# Get the merge commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
# Check if this is a PR merge
if [[ $COMMIT_MSG == "Merge pull request"* ]]; then
# Extract branch name from the merge commit message
BRANCH_NAME=$(git log -1 --pretty=%B | grep -o "from.*" | cut -d'/' -f2 | tr -d "'")
if [[ ! -z "$BRANCH_NAME" ]]; then
echo "version_tag=$BRANCH_NAME" >> $GITHUB_ENV
echo "Found branch name: $BRANCH_NAME"
else
# Fallback to commit SHA if branch name not found
echo "version_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "Using commit SHA as fallback"
fi
else
# Not a PR merge, use commit SHA
echo "version_tag=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "Using commit SHA (not a PR merge)"
fi
else
# For manual triggers, use timestamp
echo "version_tag=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV
echo "Using timestamp (manual trigger)"
fi
- name: List files in repository
run: |
echo "Contents of upwork-job-scraper directory:"
ls -al upwork-job-scraper/
- name: Create a zip file with specific files
run: |
# Start fresh - remove any existing files
rm -rf temp releases
# Create our directory structure
mkdir -p releases
mkdir -p temp
# Debug: Print current directory and structure
echo "Current directory structure:"
pwd
ls -la
files=(
activityLog.js
background.js
errorHandling.js
icon128.png
icon48.png
jobScraping.js
manifest.json
notifications.js
sentry-init.js
sentry.js
settings.css
settings.html
settings.js
utils.js
webhook.js
)
# First, create our target directory structure
mkdir -p "temp/upwork-job-scraper"
# Copy files to the correct location
echo "Copying files..."
for file in "${files[@]}"; do
if [[ -f "upwork-job-scraper/$file" ]]; then
cp "upwork-job-scraper/$file" "temp/upwork-job-scraper/"
echo "✓ Copied $file"
else
echo "❌ Error: upwork-job-scraper/$file does not exist."
exit 1
fi
done
# Create the zip file - IMPORTANT: We're in the root and specifically targeting the folder
echo "Creating zip file..."
(cd temp && zip -rf "../releases/upwork-job-scraper-${{ env.version_tag }}.zip" "upwork-job-scraper")
# Verify zip contents
echo "Verifying zip contents..."
unzip -l "releases/upwork-job-scraper-${{ env.version_tag }}.zip"
# Clean up
rm -rf temp
echo "✓ Zip file created successfully in releases folder"
- name: Commit and push releases folder
run: |
# Debug: Show git status
echo "Git status before commit:"
git status
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Force add the releases directory
git add -f releases/
# Debug: Show git status after add
echo "Git status after add:"
git status
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Add release zip for version ${{ env.version_tag }}"
git push
fi
- name: Upload zip file as artifact
uses: actions/upload-artifact@v3
with:
name: "upwork-job-scraper-${{ env.version_tag }}"
path: "releases/upwork-job-scraper-${{ env.version_tag }}.zip"
retention-days: 5 # Keep artifacts for 5 days