Skip to content

Commit 3b6bd08

Browse files
committed
Use GitHub Actions to release on tag
Update release.sh to only update changelog and tag.
1 parent c7e6b1e commit 3b6bd08

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

.github/workflows/rust.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,39 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
11-
- uses: actions/checkout@v1
12-
- name: Build
13-
run: cargo build --verbose
14-
- name: Run tests
15-
run: cargo test --verbose
9+
- uses: actions/checkout@v1
10+
- name: Build
11+
run: cargo build --all-targets --verbose
12+
- name: Run tests
13+
run: cargo test --verbose
14+
release:
15+
runs-on: ubuntu-latest
16+
needs: build
17+
if: startsWith(github.ref, 'refs/tags/')
18+
steps:
19+
- uses: actions/checkout@v1
20+
- name: Get the changelog
21+
id: get_changes
22+
run: |
23+
changelog=$(sed '/^## '"${GITHUB_REF#refs/tags/}"'.*/,/^## .*/!d;//d' CHANGELOG)
24+
changelog="${changelog//'%'/'%25'}"
25+
changelog="${changelog//$'\n'/'%0A'}"
26+
changelog="${changelog//$'\r'/'%0D'}"
27+
echo "::set-output name=changelog::${changelog}"
28+
- name: Create Release
29+
id: create_release
30+
uses: actions/create-release@latest
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
with:
34+
tag_name: ${{ github.ref }}
35+
release_name: ${{ github.ref }}
36+
body: "${{ steps.get_changes.outputs.changelog }}"
37+
draft: false
38+
prerelease: true
39+
- name: Publish
40+
env:
41+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
42+
run: cargo publish --verbose

release.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ echo -e "\\n# Checking version number\\n"
1111
git fetch
1212
git tag --list | grep -q "${version}" && echo "Error: Git tag ${version} already exists" && exit 1
1313

14-
echo -e "\\n# Checking GitHub credentials\\n"
15-
[[ -n ${GITHUB_TOKEN+x} ]] || (echo "Error: GITHUB_TOKEN variable not set" && exit 1)
16-
curl --fail --silent --output /dev/null -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/user
17-
18-
echo -e "\\n# Checking crates.io credentials\\n"
19-
[[ -f ~/.cargo/credentials ]] || (echo "Error: crates.io credentials not present" && exit 1)
20-
cargo publish --dry-run --quiet
21-
2214
echo -e "\\n# Updating version number in files\\n"
2315
sed --in-place "s/version = \".*\"/version = \"${version}\"/" Cargo.toml
2416
sed --in-place "s/## Unreleased/## Unreleased\\n\\n## ${version} - ${date}/" CHANGELOG
@@ -27,16 +19,8 @@ echo -e "\\n# Adding to Git\\n"
2719
git add Cargo.toml CHANGELOG
2820
git commit -m "Update version numbers for ${version}"
2921

30-
echo -e "\\n# Publishing crate\\n"
31-
cargo publish
32-
3322
echo -e "\\n# Pushing to Git\\n"
3423
git tag "${version}"
3524
git push origin --tags
3625

37-
echo -e "\\n# Publishing GitHub release\\n"
38-
changes=$(sed '/^## '"${version}"'.*/,/^## .*/!d;//d' CHANGELOG)
39-
changes=$(echo "${changes}" | awk '{printf "%s\\n", $0}')
40-
curl -H "Authorization: token ${GITHUB_TOKEN}" -d '{"tag_name": "'"${version}"'", "name": "'"${version}"'", "body": "'"${changes}"'"}' https://api.github.com/repos/milliams/plotlib/releases | jq
41-
4226
echo -e "\\n# Success ✓"

0 commit comments

Comments
 (0)