Skip to content

Commit a3cb8e4

Browse files
committed
wip
automatically-tag-and-release-this-commit
1 parent 1a30482 commit a3cb8e4

File tree

5 files changed

+107
-69
lines changed

5 files changed

+107
-69
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: 'TODO'
2+
description: 'TODO'
3+
4+
inputs:
5+
cargo_token:
6+
description: 'TODO'
7+
required: false
8+
9+
runs:
10+
using: composite
11+
steps:
12+
# If this is a push to `main` see if the push has an indicator saying that
13+
# a tag should be made. If so create one and push it.
14+
- name: Test if tag is needed
15+
run: |
16+
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
17+
version=$(./ci/print-current-version.sh)
18+
echo "version: $version"
19+
echo "version=$version" >> $GITHUB_OUTPUT
20+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
21+
if grep -q "automatically-tag-and-release-this-commit" main.log; then
22+
echo push-tag
23+
echo "push_tag=yes" >> $GITHUB_OUTPUT
24+
else
25+
echo no-push-tag
26+
echo "push_tag=no" >> $GITHUB_OUTPUT
27+
fi
28+
shell: bash
29+
id: tag
30+
31+
- name: Push the tag
32+
run: |
33+
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
34+
curl -iX POST $git_refs_url \
35+
-H "Authorization: token ${{ github.token }}" \
36+
-d @- << EOF
37+
{
38+
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
39+
"sha": "${{ steps.tag.outputs.sha }}"
40+
}
41+
EOF
42+
shell: bash
43+
if: steps.tag.outputs.push_tag == 'yes'
44+
45+
- run: |
46+
sha=${{ github.sha }}
47+
run_id=$(
48+
gh api -H 'Accept: application/vnd.github+json' \
49+
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
50+
| jq '.workflow_runs' \
51+
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
52+
)
53+
gh run download $run_id
54+
ls
55+
find bins-*
56+
mkdir dist
57+
mv bins-*/* dist
58+
shell: bash
59+
env:
60+
GH_TOKEN: ${{ github.token }}
61+
62+
- uses: softprops/action-gh-release@v1
63+
if: steps.tag.outputs.push_tag == 'yes'
64+
with:
65+
files: "dist/*"
66+
generate_release_notes: true
67+
tag_name: v${{ steps.tag.outputs.version }}
68+
69+
- run: rustup update stable && rustup default stable
70+
shell: bash
71+
72+
- run: |
73+
rm -rf dist main.log
74+
rustc ci/publish.rs
75+
./publish publish
76+
shell: bash
77+
env:
78+
CARGO_REGISTRY_TOKEN: ${{ inputs.cargo_token }}
79+
if: steps.tag.outputs.push_tag == 'yes' && github.repository_owner == 'bytecodealliance'

.github/workflows/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
name: CI
22
on:
3+
# Run CI for PRs to `main` and to release branches.
34
pull_request:
5+
# This is the CI that runs for PRs-to-merge.
46
merge_group:
7+
# Run full CI on pushes to release branches since the merge queue can't be
8+
# used with for all release branches (wildcard pattern turns that off)
9+
push:
10+
branches:
11+
- 'release-*'
512

613
# Cancel any in-flight jobs for the same PR/branch so there's only one active
714
# at a time
@@ -331,3 +338,20 @@ jobs:
331338
- name: Report failure on cancellation
332339
if: ${{ contains(needs.*.result, 'cancelled') || cancelled() }}
333340
run: exit 1
341+
342+
maybe-trigger-tag:
343+
runs-on: ubuntu-latest
344+
needs: ci-status
345+
if: |
346+
always()
347+
&& needs.ci-status.result == 'success'
348+
&& github.event_name == 'push'
349+
&& startsWith(github.ref, 'refs/heads/release-')
350+
steps:
351+
- uses: actions/checkout@v4
352+
with:
353+
submodules: true
354+
fetch-depth: 0
355+
- uses: ./.github/actions/publish-release
356+
with:
357+
cargo_token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/playground.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
deploy:
4848
name: Deploy playground
49-
if: github.ref == 'refs/heads/main'
49+
if: github.ref == 'refs/heads/main' && github.repository_owner == 'bytecodealliance'
5050
needs: build
5151
permissions:
5252
pages: write

.github/workflows/publish.yml

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,11 @@ jobs:
1414
create_tag:
1515
name: Publish artifacts of build
1616
runs-on: ubuntu-latest
17-
if: |
18-
github.repository_owner == 'bytecodealliance'
19-
&& github.event_name == 'push'
20-
&& github.ref == 'refs/heads/main'
2117
steps:
2218
- uses: actions/checkout@v4
2319
with:
2420
submodules: true
2521
fetch-depth: 0
26-
27-
- run: rustup update stable && rustup default stable
28-
29-
# If this is a push to `main` see if the push has an indicator saying that
30-
# a tag should be made. If so create one and push it.
31-
- name: Test if tag is needed
32-
run: |
33-
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
34-
version=$(./ci/print-current-version.sh)
35-
echo "version: $version"
36-
echo "version=$version" >> $GITHUB_OUTPUT
37-
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
38-
if grep -q "automatically-tag-and-release-this-commit" main.log; then
39-
echo push-tag
40-
echo "push_tag=yes" >> $GITHUB_OUTPUT
41-
else
42-
echo no-push-tag
43-
echo "push_tag=no" >> $GITHUB_OUTPUT
44-
fi
45-
id: tag
46-
47-
- name: Push the tag
48-
run: |
49-
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
50-
curl -iX POST $git_refs_url \
51-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
52-
-d @- << EOF
53-
{
54-
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
55-
"sha": "${{ steps.tag.outputs.sha }}"
56-
}
57-
EOF
58-
if: steps.tag.outputs.push_tag == 'yes'
59-
60-
- run: |
61-
sha=${{ github.sha }}
62-
run_id=$(
63-
gh api -H 'Accept: application/vnd.github+json' \
64-
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
65-
| jq '.workflow_runs' \
66-
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
67-
)
68-
gh run download $run_id
69-
ls
70-
find bins-*
71-
mkdir dist
72-
mv bins-*/* dist
73-
env:
74-
GH_TOKEN: ${{ github.token }}
75-
76-
- uses: softprops/action-gh-release@v1
77-
if: steps.tag.outputs.push_tag == 'yes'
22+
- uses: ./.github/actions/publish-release
7823
with:
79-
files: "dist/*"
80-
generate_release_notes: true
81-
tag_name: v${{ steps.tag.outputs.version }}
82-
83-
- run: |
84-
rm -rf dist main.log
85-
rustc ci/publish.rs
86-
./publish publish
87-
env:
88-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
89-
if: steps.tag.outputs.push_tag == 'yes'
24+
cargo_token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/release-process.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
git push origin HEAD:ci/release-$cur
5757
echo "PR_HEAD=ci/release-$cur" >> $GITHUB_ENV
5858
echo "PR_TITLE=Release ${{ github.event.repository.name }} $cur" >> $GITHUB_ENV
59-
echo "PR_BASE=main" >> $GITHUB_ENV
59+
echo "PR_BASE=${{ github.ref_name }}" >> $GITHUB_ENV
6060
cat > pr-body <<-EOF
6161
This is an automated pull request from CI to release
6262
${{ github.event.repository.name }} $cur when merged. The commit

0 commit comments

Comments
 (0)