-
Notifications
You must be signed in to change notification settings - Fork 197
88 lines (79 loc) · 2.72 KB
/
publish.yml
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
# Publication half of the release process for this repository. This runs on
# pushes to `main` and will detect a magical string in commit messages. When
# found a tag will be created, pushed, and then everything is published.
name: Publish Artifacts
on:
push:
branches: [main]
permissions:
contents: write
jobs:
create_tag:
name: Publish artifacts of build
runs-on: ubuntu-latest
if: |
github.repository_owner == 'bytecodealliance'
&& github.event_name == 'push'
&& github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- run: rustup update stable && rustup default stable
# If this is a push to `main` see if the push has an indicator saying that
# a tag should be made. If so create one and push it.
- name: Test if tag is needed
run: |
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
version=$(./ci/print-current-version.sh)
echo "version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
if grep -q "automatically-tag-and-release-this-commit" main.log; then
echo push-tag
echo "push_tag=yes" >> $GITHUB_OUTPUT
else
echo no-push-tag
echo "push_tag=no" >> $GITHUB_OUTPUT
fi
id: tag
- name: Push the tag
run: |
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
curl -iX POST $git_refs_url \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d @- << EOF
{
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
"sha": "${{ steps.tag.outputs.sha }}"
}
EOF
if: steps.tag.outputs.push_tag == 'yes'
- run: |
sha=${{ github.sha }}
run_id=$(
gh api -H 'Accept: application/vnd.github+json' \
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
| jq '.workflow_runs' \
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
)
gh run download $run_id
ls
find bins-*
mkdir dist
mv bins-*/* dist
env:
GH_TOKEN: ${{ github.token }}
- uses: softprops/action-gh-release@v1
if: steps.tag.outputs.push_tag == 'yes'
with:
files: "dist/*"
tag_name: v${{ steps.tag.outputs.version }}
- run: |
rm -rf dist main.log
rustc ci/publish.rs
./publish publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
if: steps.tag.outputs.push_tag == 'yes'