1+ # .github/workflows/deploy.yml
2+
3+ name : Build and Deploy to Releases Branch
4+
5+ on :
6+ push :
7+ tags :
8+ - ' v*.*.*'
9+
10+ jobs :
11+ deploy :
12+ runs-on : ubuntu-latest
13+ permissions :
14+ contents : write
15+
16+ steps :
17+ - name : Checkout repository
18+ uses : actions/checkout@v4
19+
20+ - name : Install Deno
21+ uses : denoland/setup-deno@v2
22+ with :
23+ deno-version : v2.x
24+
25+ - name : Build project
26+ run : deno task build
27+
28+ - name : Get version from Git tag
29+ id : get_version
30+ run : echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
31+
32+ - name : Deploy artifacts to releases branch
33+ run : |
34+ # 1. Configure Git for the Actions bot
35+ git config --global user.name "github-actions[bot]"
36+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
37+
38+ # 2. Clone the releases branch into a separate directory
39+ # Using a token is necessary for pushing from a workflow
40+ git clone --branch=releases --single-branch https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git deploy_dir
41+
42+ # 3. Copy build files into versioned and latest directories
43+ cd deploy_dir
44+ rm -rf latest/* # Clear previous 'latest' build
45+ mkdir -p ${{ env.VERSION }}
46+ mkdir -p latest
47+ cp -r ../dist/. ./${{ env.VERSION }}
48+ cp -r ../dist/. ./latest
49+
50+ # 4. Generate a new README with links to all versions
51+ echo "# Project Releases" > README.md
52+ echo "" >> README.md
53+ echo "This branch contains production-ready build artifacts for each version." >> README.md
54+ echo "" >> README.md
55+ echo "## Latest Version" >> README.md
56+ echo "- **[latest](./latest)**" >> README.md
57+ echo "" >> README.md
58+ echo "## All Versions" >> README.md
59+ # Find all version directories (v*), sort them naturally (v1.10.0 after v1.2.0),
60+ # reverse the order, and format as a markdown list.
61+ ls -d v* | sort -V -r | sed 's/^/- [&](.\/&)/' >> README.md
62+
63+ # 5. Commit and push the changes to the releases branch
64+ git add .
65+ if git diff --staged --quiet; then
66+ echo "No changes to commit. Skipping."
67+ else
68+ git commit -m "Deploy: Add artifacts for version ${{ env.VERSION }}"
69+ git push
70+ fi
0 commit comments