-
Notifications
You must be signed in to change notification settings - Fork 2
189 lines (166 loc) · 7.53 KB
/
Copy pathrelease.yml
File metadata and controls
189 lines (166 loc) · 7.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Release
on:
push:
branches: [main]
jobs:
release:
name: Tag & Publish
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
tag: ${{ steps.version.outputs.tag }}
version: ${{ steps.version.outputs.version }}
created: ${{ steps.check.outputs.exists == 'false' }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Get version from Cargo.toml
id: version
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if tag already exists
id: check
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create git tag
if: steps.check.outputs.exists == 'false'
run: |
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
if: steps.check.outputs.exists == 'false'
- name: Publish to crates.io
if: steps.check.outputs.exists == 'false'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish || echo "::warning::crates.io publish skipped (version may already exist)"
- name: Create GitHub Release
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--generate-notes
build-binaries:
name: Build (${{ matrix.target }})
needs: release
if: needs.release.outputs.created == 'true'
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: ${{ matrix.target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: matrix.archive == 'tar.gz'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../parsec-${{ needs.release.outputs.version }}-${{ matrix.target }}.tar.gz parsec
cd ../../..
- name: Package (windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
Compress-Archive -Path "target/${{ matrix.target }}/release/parsec.exe" -DestinationPath "parsec-${{ needs.release.outputs.version }}-${{ matrix.target }}.zip"
- name: Upload to GitHub Release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload "${{ needs.release.outputs.tag }}" \
parsec-${{ needs.release.outputs.version }}-${{ matrix.target }}.${{ matrix.archive }} \
--clobber
snapshot-docs:
name: Snapshot Versioned Docs
needs: release
if: needs.release.outputs.created == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: main
- name: Create versioned docs snapshot
env:
VERSION: ${{ needs.release.outputs.version }}
run: |
mkdir -p "docs/v/${VERSION}/guide" "docs/v/${VERSION}/reference"
for file in index.html guide/index.html reference/index.html; do
sed \
-e 's/data-doc-version="latest"/data-doc-version="'"${VERSION}"'"/' \
-e 's|<meta charset="UTF-8">|<meta charset="UTF-8">\n <meta name="robots" content="noindex, follow">|' \
-e 's|href="/git-parsec/"|href="/git-parsec/v/'"${VERSION}"'/"|g' \
-e 's|href="/git-parsec/#|href="/git-parsec/v/'"${VERSION}"'/#|g' \
-e 's|href="/git-parsec/reference/|href="/git-parsec/v/'"${VERSION}"'/reference/|g' \
-e 's|href="/git-parsec/guide/|href="/git-parsec/v/'"${VERSION}"'/guide/|g' \
-e 's|src="demo.gif"|src="/git-parsec/demo.gif"|' \
"docs/${file}" > "docs/v/${VERSION}/${file}"
done
- name: Update versions.json
env:
VERSION: ${{ needs.release.outputs.version }}
run: |
DATE=$(date -u +%Y-%m-%d)
jq --arg ver "$VERSION" --arg date "$DATE" \
'.latest = $ver | .versions = [{"version": $ver, "date": $date, "path": ("/git-parsec/v/" + $ver + "/")}] + .versions' \
docs/versions.json > docs/versions.json.tmp
mv docs/versions.json.tmp docs/versions.json
- name: Update sitemap.xml
env:
VERSION: ${{ needs.release.outputs.version }}
run: |
DATE=$(date -u +%Y-%m-%d)
sed -i '/<\/urlset>/i \
<url>\n <loc>https://erishforg.github.io/git-parsec/v/'"${VERSION}"'/</loc>\n <lastmod>'"${DATE}"'</lastmod>\n <changefreq>never</changefreq>\n <priority>0.3</priority>\n </url>\n <url>\n <loc>https://erishforg.github.io/git-parsec/v/'"${VERSION}"'/guide/</loc>\n <lastmod>'"${DATE}"'</lastmod>\n <changefreq>never</changefreq>\n <priority>0.3</priority>\n </url>\n <url>\n <loc>https://erishforg.github.io/git-parsec/v/'"${VERSION}"'/reference/</loc>\n <lastmod>'"${DATE}"'</lastmod>\n <changefreq>never</changefreq>\n <priority>0.3</priority>\n </url>' docs/sitemap.xml
- name: Open snapshot PR (main is protected — push direct is blocked)
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
base: main
branch: docs/snapshot-v${{ needs.release.outputs.version }}
commit-message: "docs: snapshot versioned docs for v${{ needs.release.outputs.version }}"
title: "docs: snapshot versioned docs for v${{ needs.release.outputs.version }}"
body: |
Automated docs snapshot for **v${{ needs.release.outputs.version }}** (release run #${{ github.run_id }}).
Produced by `.github/workflows/release.yml` → `snapshot-docs` job.
## Files
- `docs/v/${{ needs.release.outputs.version }}/{index,guide/index,reference/index}.html` — versioned docs (with `noindex` meta)
- `docs/versions.json` — `latest` bump + history entry
- `docs/sitemap.xml` — versioned URLs added
Safe to merge. No code change, only doc data.
labels: |
release
auto-snapshot
author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
delete-branch: true