Skip to content

Commit 2eef577

Browse files
committed
Reorganise CI, publish on version change
1 parent 0cc37a1 commit 2eef577

File tree

3 files changed

+105
-89
lines changed

3 files changed

+105
-89
lines changed

.github/workflows/antlr.yml

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ANTLR4 testsuite
1+
name: CI
22

33
on:
44
push:
@@ -8,26 +8,32 @@ on:
88

99
workflow_dispatch:
1010

11+
env:
12+
CARGO_TERM_COLOR: always
13+
RUST_VERSION: nightly-2021-04-23
14+
1115
jobs:
12-
build:
16+
tests-antlr:
17+
name: ANTLR4 testsuite
1318
runs-on: ubuntu-latest
14-
1519
steps:
1620
- uses: actions/checkout@v2
1721
with:
1822
repository: rrevenantt/antlr4
1923
ref: rust-target
2024
submodules: true
21-
- run: git fetch origin $GITHUB_REF
25+
- run: |
26+
git fetch origin $GITHUB_REF
27+
git checkout FETCH_HEAD
2228
working-directory: runtime/Rust
2329
- name: Set up JDK 1.8
2430
uses: actions/setup-java@v1
2531
with:
2632
java-version: 1.8
2733
- name: Install Rust
28-
uses: actions-rs/toolchain@v1.0.6
34+
uses: actions-rs/toolchain@v1
2935
with:
30-
toolchain: nightly-2020-12-23
36+
toolchain: ${{ env.RUST_VERSION }}
3137
default: true
3238
- name: Cache local Maven repository
3339
uses: actions/cache@v2
@@ -51,4 +57,96 @@ jobs:
5157
name: antlr-tool
5258
path: tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar
5359

54-
60+
tests-rust:
61+
name: cargo test
62+
runs-on: ubuntu-latest
63+
outputs:
64+
new_version: ${{ steps.check_ver.outputs.new_version }}
65+
steps:
66+
- uses: actions/checkout@v2
67+
- name: Install Rust
68+
uses: actions-rs/toolchain@v1
69+
with:
70+
toolchain: ${{ env.RUST_VERSION }}
71+
default: true
72+
components: rustfmt
73+
- name: Build
74+
run: cargo build --verbose
75+
- name: Run tests
76+
run: cargo test --verbose
77+
- name: Formatting
78+
run: cargo fmt -- --check
79+
- uses: actions/checkout@v2
80+
if: ${{ github.event_name == 'push' }}
81+
with:
82+
ref: ${{ github.event.before }}
83+
path: base_branch
84+
- name: check version bump
85+
if: ${{ github.event_name == 'push' }}
86+
id: check_ver
87+
run: |
88+
NEW_VER = $(cat Cargo.toml | sed -nE "s/^version.*\"([0-9a-z.\-]+)\".*$/\1/p")
89+
BASE_VER = $(cat base_branch/Cargo.toml | sed -nE "s/^version.*\"([0-9a-z.\-]+)\".*$/\1/p")
90+
if [[ "$s1" != "$s2" ]] then
91+
echo "::set-output name=new_version::$NEW_VER"
92+
fi
93+
94+
publish:
95+
runs-on: ubuntu-latest
96+
if: |
97+
success() && github.event_name == 'push'
98+
&& needs.tests-rust.outputs.new_version != null
99+
&& needs.tests-rust.outputs.new_version != ''
100+
needs: [tests-rust,tests-antlr]
101+
env:
102+
RELEASE_NAME: ${{ format('antlr4-4.8-2-Rust{0}',needs.tests-rust.outputs.new_version) }}
103+
PRERELEASE: ${{ contains(needs.tests-rust.outputs.new_version, '-') }}
104+
steps:
105+
- uses: actions/checkout@v2
106+
- name: Install Rust
107+
uses: actions-rs/toolchain@v1
108+
with:
109+
toolchain: ${{ env.RUST_VERSION }}
110+
default: true
111+
- name: Cargo publish check
112+
env:
113+
CRATES_IO_PUBLISH_TOKEN: ${{ secrets.CRATES_IO_PUBLISH_TOKEN }}
114+
run: |
115+
cargo login $CRATES_IO_PUBLISH_TOKEN
116+
cargo publish --dry-run
117+
- uses: actions/download-artifact@v2
118+
with:
119+
name: antlr-tool
120+
- name: Create release
121+
id: create_release
122+
uses: actions/create-release@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
with:
126+
tag_name: ${{ env.RELEASE_NAME }}
127+
release_name: ${{ env.RELEASE_NAME }}
128+
# make release a draft first in case `cargo publish` still fail
129+
draft: true
130+
prerelease: ${{ env.PRERELEASE }}
131+
- name: Upload Release Asset
132+
uses: actions/upload-release-asset@v1
133+
env:
134+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
with:
136+
upload_url: ${{ steps.create_release.outputs.upload_url }}
137+
asset_path: antlr4-4.8-2-SNAPSHOT-complete.jar
138+
asset_name: antlr4-4.8-2-SNAPSHOT-complete.jar
139+
asset_content_type: application/java-archive
140+
- name: Cargo publish
141+
run: cargo publish
142+
- name: Publish github release
143+
uses: actions/create-release@v1
144+
env:
145+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
with:
147+
release_name: ${{ env.RELEASE_NAME }}
148+
allowUpdates: true
149+
omitNameDuringUpdate: true
150+
omitPrereleaseDuringUpdate: true
151+
replacesArtifacts: false
152+
draft: false

.github/workflows/publish.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/rust.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)