Skip to content

Commit 0a7b306

Browse files
Refactor GitHub workflows for consistency and readability (#112)
1 parent 4817197 commit 0a7b306

File tree

3 files changed

+279
-256
lines changed

3 files changed

+279
-256
lines changed

.github/workflows/codeql.yml

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ name: "CodeQL"
22

33
on:
44
push:
5-
branches: [ "main", "develop" ]
5+
branches: ["main", "develop"]
66
pull_request:
7-
branches: [ "main", "develop" ]
7+
branches: ["main", "develop"]
88
schedule:
9-
- cron: '21 17 * * 0' # Weekly on Sundays at 17:21 UTC
9+
- cron: "21 17 * * 0" # Weekly on Sundays at 17:21 UTC
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
1014

1115
jobs:
1216
analyze:
@@ -26,55 +30,55 @@ jobs:
2630
fail-fast: false
2731
matrix:
2832
include:
29-
- language: rust
30-
build-mode: none
33+
- language: rust
34+
build-mode: none
3135
# Add other languages if your repository contains them
3236
# - language: javascript-typescript
3337
# build-mode: none
3438

3539
steps:
36-
- name: Checkout repository
37-
uses: actions/checkout@v4
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
3842

39-
# Cache Rust dependencies to speed up builds
40-
- name: Cache Rust dependencies
41-
if: matrix.language == 'rust'
42-
uses: actions/cache@v4
43-
with:
44-
path: |
45-
~/.cargo/bin/
46-
~/.cargo/registry/index/
47-
~/.cargo/registry/cache/
48-
~/.cargo/git/db/
49-
target/
50-
key: ${{ runner.os }}-cargo-codeql-${{ hashFiles('**/Cargo.lock') }}
51-
restore-keys: |
52-
${{ runner.os }}-cargo-codeql-
53-
${{ runner.os }}-cargo-
43+
# Cache Rust dependencies to speed up builds
44+
- name: Cache Rust dependencies
45+
if: matrix.language == 'rust'
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
~/.cargo/bin/
50+
~/.cargo/registry/index/
51+
~/.cargo/registry/cache/
52+
~/.cargo/git/db/
53+
target/
54+
key: ${{ runner.os }}-cargo-codeql-${{ hashFiles('**/Cargo.lock') }}
55+
restore-keys: |
56+
${{ runner.os }}-cargo-codeql-
57+
${{ runner.os }}-cargo-
5458
55-
# Initializes the CodeQL tools for scanning.
56-
- name: Initialize CodeQL
57-
uses: github/codeql-action/init@v3
58-
with:
59-
languages: ${{ matrix.language }}
60-
build-mode: ${{ matrix.build-mode }}
61-
# If you wish to specify custom queries, you can do so here or in a config file.
62-
# By default, queries listed here will override any specified in a config file.
63-
# Prefix the list here with "+" to use these queries and those in the config file.
64-
# For more details on CodeQL's query suites, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
65-
# queries: security-extended,security-and-quality
59+
# Initializes the CodeQL tools for scanning.
60+
- name: Initialize CodeQL
61+
uses: github/codeql-action/init@v3
62+
with:
63+
languages: ${{ matrix.language }}
64+
build-mode: ${{ matrix.build-mode }}
65+
# If you wish to specify custom queries, you can do so here or in a config file.
66+
# By default, queries listed here will override any specified in a config file.
67+
# Prefix the list here with "+" to use these queries and those in the config file.
68+
# For more details on CodeQL's query suites, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
69+
# queries: security-extended,security-and-quality
6670

67-
# For Rust with build-mode: none, CodeQL handles the build automatically
68-
- name: Install Rust toolchain
69-
if: matrix.language == 'rust'
70-
uses: actions-rust-lang/setup-rust-toolchain@v1
71-
with:
72-
toolchain: stable
73-
target: wasm32-unknown-unknown
74-
# Enable caching in the Rust toolchain setup
75-
cache: true
71+
# For Rust with build-mode: none, CodeQL handles the build automatically
72+
- name: Install Rust toolchain
73+
if: matrix.language == 'rust'
74+
uses: actions-rust-lang/setup-rust-toolchain@v1
75+
with:
76+
toolchain: stable
77+
target: wasm32-unknown-unknown
78+
# Enable caching in the Rust toolchain setup
79+
cache: true
7680

77-
- name: Perform CodeQL Analysis
78-
uses: github/codeql-action/analyze@v3
79-
with:
80-
category: "/language:${{matrix.language}}"
81+
- name: Perform CodeQL Analysis
82+
uses: github/codeql-action/analyze@v3
83+
with:
84+
category: "/language:${{matrix.language}}"

.github/workflows/release.yml

Lines changed: 130 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,63 @@ name: Release SpacetimeDSL
22

33
on:
44
push:
5-
tags: [ 'v*' ] # Trigger release only on version tags
5+
tags: ["v*"] # Trigger release only on version tags
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
610

711
jobs:
812
# Verify tests passed before release
913
verify-tests:
10-
name: Verify tests passed
14+
name: Verify tests passed
1115
runs-on: ubuntu-latest
1216
steps:
13-
- name: Check latest workflow run
14-
uses: actions/github-script@v7
15-
with:
16-
script: |
17-
// Get the commit SHA for the tag
18-
const tagRef = context.ref;
19-
const tagSha = context.sha;
20-
21-
console.log(`Checking tests for tag ${tagRef} (${tagSha})`);
22-
23-
// Get recent workflow runs for the test workflow
24-
const { data: workflows } = await github.rest.actions.listWorkflowRuns({
25-
owner: context.repo.owner,
26-
repo: context.repo.repo,
27-
workflow_id: 'test.yml',
28-
head_sha: tagSha,
29-
per_page: 1
30-
});
31-
32-
if (workflows.total_count === 0) {
33-
console.log('⚠️ No test workflow found for this commit');
34-
console.log('This might be expected if this is the first run after adding the tag trigger');
35-
return;
36-
}
37-
38-
const latestRun = workflows.workflow_runs[0];
39-
console.log(`Latest test run: ${latestRun.status} (${latestRun.conclusion})`);
40-
41-
if (latestRun.conclusion !== 'success') {
42-
console.log('❌ Tests did not pass - release cannot proceed');
17+
- name: Wait for test workflow to complete
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const tagRef = context.ref;
22+
const tagSha = context.sha;
23+
const pollIntervalMs = 30_000; // 30 seconds
24+
const timeoutMs = 30 * 60_000; // 30 minutes
25+
26+
console.log(`Waiting for test workflow to pass for tag ${tagRef} (${tagSha})`);
27+
28+
const startTime = Date.now();
29+
30+
while (Date.now() - startTime < timeoutMs) {
31+
const { data: workflows } = await github.rest.actions.listWorkflowRuns({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
workflow_id: 'test.yml',
35+
head_sha: tagSha,
36+
per_page: 1
37+
});
38+
39+
if (workflows.total_count === 0) {
40+
console.log('⏳ No test workflow run found yet, waiting...');
41+
} else {
42+
const run = workflows.workflow_runs[0];
43+
console.log(`Test run status: ${run.status}, conclusion: ${run.conclusion}`);
44+
45+
if (run.status === 'completed') {
46+
if (run.conclusion === 'success') {
47+
console.log('✅ Tests passed - release can proceed');
48+
return;
49+
}
50+
console.log('❌ Tests did not pass - release cannot proceed');
51+
process.exit(1);
52+
}
53+
54+
console.log('⏳ Test workflow still running, waiting...');
55+
}
56+
57+
await new Promise(r => setTimeout(r, pollIntervalMs));
58+
}
59+
60+
console.log('❌ Timed out waiting for test workflow to complete');
4361
process.exit(1);
44-
}
45-
46-
console.log('✅ Tests passed - release can proceed');
4762
4863
# Release job - publishes to crates.io when version tags are pushed
4964
release:
@@ -53,85 +68,85 @@ jobs:
5368
# Use GitHub environment for enhanced security and manual approval if desired
5469
environment: release
5570
permissions:
56-
id-token: write # Required for OIDC token exchange with crates.io
57-
contents: read # Required to read repository contents
71+
id-token: write # Required for OIDC token exchange with crates.io
72+
contents: read # Required to read repository contents
5873

5974
steps:
60-
- name: Checkout code
61-
uses: actions/checkout@v4
62-
63-
- name: Extract version from tag
64-
id: version
65-
run: |
66-
# Extract version from tag (e.g., refs/tags/v0.10.0 -> 0.10.0)
67-
VERSION=${GITHUB_REF#refs/tags/v}
68-
echo "version=$VERSION" >> $GITHUB_OUTPUT
69-
echo "Extracted version: $VERSION"
70-
echo "🏷️ Release triggered by tag: ${{ github.ref }}"
71-
72-
- name: Install Rust toolchain
73-
uses: actions-rust-lang/setup-rust-toolchain@v1
74-
with:
75-
toolchain: stable
76-
77-
# Authenticate with crates.io using OIDC/Trusted Publishing
78-
- name: Authenticate with crates.io
79-
id: auth
80-
uses: rust-lang/crates-io-auth-action@v1
81-
82-
- name: Validate crate publishing readiness
83-
run: |
84-
cargo check
85-
cargo build
86-
87-
# Publish derive-input crate first (no dependencies)
88-
- name: Publish spacetimedsl_derive-input to crates.io
89-
run: |
90-
echo "Publishing spacetimedsl_derive-input..."
91-
cd derive-input
92-
cargo publish
93-
echo "✅ spacetimedsl_derive-input published successfully"
94-
cd ..
95-
env:
96-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
97-
98-
# Verify derive-input crate is available before proceeding
99-
- name: Verify spacetimedsl_derive-input availability
100-
uses: ./.github/actions/verify-crate-availability
101-
with:
102-
crate-name: spacetimedsl_derive-input
103-
version: ${{ steps.version.outputs.version }}
104-
105-
# Publish derive crate second (depends on derive-input)
106-
- name: Publish spacetimedsl_derive to crates.io
107-
run: |
108-
echo "Publishing spacetimedsl_derive..."
109-
cd derive
110-
cargo publish
111-
echo "✅ spacetimedsl_derive published successfully"
112-
cd ..
113-
env:
114-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
115-
116-
# Verify derive crate is available before proceeding
117-
- name: Verify spacetimedsl_derive availability
118-
uses: ./.github/actions/verify-crate-availability
119-
with:
120-
crate-name: spacetimedsl_derive
121-
version: ${{ steps.version.outputs.version }}
122-
123-
# Publish main crate last (depends on derive)
124-
- name: Publish spacetimedsl to crates.io
125-
run: |
126-
echo "Publishing spacetimedsl (main crate)..."
127-
cargo publish
128-
echo "✅ All crates published successfully! 🎉"
129-
env:
130-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
131-
132-
# Final verification that main crate is available
133-
- name: Verify spacetimedsl availability
134-
uses: ./.github/actions/verify-crate-availability
135-
with:
136-
crate-name: spacetimedsl
137-
version: ${{ steps.version.outputs.version }}
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Extract version from tag
79+
id: version
80+
run: |
81+
# Extract version from tag (e.g., refs/tags/v0.10.0 -> 0.10.0)
82+
VERSION=${GITHUB_REF#refs/tags/v}
83+
echo "version=$VERSION" >> $GITHUB_OUTPUT
84+
echo "Extracted version: $VERSION"
85+
echo "🏷️ Release triggered by tag: ${{ github.ref }}"
86+
87+
- name: Install Rust toolchain
88+
uses: actions-rust-lang/setup-rust-toolchain@v1
89+
with:
90+
toolchain: stable
91+
92+
# Authenticate with crates.io using OIDC/Trusted Publishing
93+
- name: Authenticate with crates.io
94+
id: auth
95+
uses: rust-lang/crates-io-auth-action@v1
96+
97+
- name: Validate crate publishing readiness
98+
run: |
99+
cargo check
100+
cargo build
101+
102+
# Publish derive-input crate first (no dependencies)
103+
- name: Publish spacetimedsl_derive-input to crates.io
104+
run: |
105+
echo "Publishing spacetimedsl_derive-input..."
106+
cd derive-input
107+
cargo publish
108+
echo "✅ spacetimedsl_derive-input published successfully"
109+
cd ..
110+
env:
111+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
112+
113+
# Verify derive-input crate is available before proceeding
114+
- name: Verify spacetimedsl_derive-input availability
115+
uses: ./.github/actions/verify-crate-availability
116+
with:
117+
crate-name: spacetimedsl_derive-input
118+
version: ${{ steps.version.outputs.version }}
119+
120+
# Publish derive crate second (depends on derive-input)
121+
- name: Publish spacetimedsl_derive to crates.io
122+
run: |
123+
echo "Publishing spacetimedsl_derive..."
124+
cd derive
125+
cargo publish
126+
echo "✅ spacetimedsl_derive published successfully"
127+
cd ..
128+
env:
129+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
130+
131+
# Verify derive crate is available before proceeding
132+
- name: Verify spacetimedsl_derive availability
133+
uses: ./.github/actions/verify-crate-availability
134+
with:
135+
crate-name: spacetimedsl_derive
136+
version: ${{ steps.version.outputs.version }}
137+
138+
# Publish main crate last (depends on derive)
139+
- name: Publish spacetimedsl to crates.io
140+
run: |
141+
echo "Publishing spacetimedsl (main crate)..."
142+
cargo publish
143+
echo "✅ All crates published successfully! 🎉"
144+
env:
145+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
146+
147+
# Final verification that main crate is available
148+
- name: Verify spacetimedsl availability
149+
uses: ./.github/actions/verify-crate-availability
150+
with:
151+
crate-name: spacetimedsl
152+
version: ${{ steps.version.outputs.version }}

0 commit comments

Comments
 (0)