-
Notifications
You must be signed in to change notification settings - Fork 147
85 lines (81 loc) · 3.79 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
name: Publish
on:
release:
types: [published] # Only publish to crates.io when we formally publish a release
# For more on how to formally release on Github, read https://help.github.com/en/articles/creating-releases
jobs:
publish-rust-crate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to crates.io
run: cargo login $CRATES_IO_TOKEN
env:
CRATES_IO_TOKEN: ${{ secrets.crates_io_token }} # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
- name: Dry run publish
run: cargo publish --dry-run --manifest-path fiat-rust/Cargo.toml
- name: Publish
run: cargo publish --manifest-path fiat-rust/Cargo.toml
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.crates_io_token }}
bump-rust-crate-version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Bump Rust crate version
id: bumpRustViaPush
run: |
etc/ci/bump-fiat-rust-crate-version.sh
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git config http.sslVerify false
git config user.name "Automated Publisher"
git config user.email "[email protected]"
git remote add publisher "${remote_repo}"
git remote update
git show-ref # useful for debugging
git branch --verbose
git checkout -b temp
git branch -D master || true
git checkout -b master publisher/master
git add fiat-rust/Cargo.toml
timestamp=$(date -u)
git commit -m "Automated Rust Crate Version Bump: ${timestamp} ${GITHUB_SHA}"
if git push publisher master; then
echo "Push successful"
else
# If the push fails, get the short SHA of the latest commit
SHORT_SHA=$(git rev-parse --short HEAD)
# Create and push to a new branch
git checkout -b rust-crate-version-bump-$SHORT_SHA
git push --set-upstream publisher rust-crate-version-bump-$SHORT_SHA
FAILURE_MESSAGE="PR creation failed"
# Locate workflow file, remove the Git ref at the end
WORKFLOW_PATH="${GITHUB_WORKFLOW_REF%@*}"
# Split the string to insert the blob/SHA part correctly
REPO_PATH="${WORKFLOW_PATH%/.github/*}" # This extracts 'everything before /.github/'
WORKFLOW_FILE_PATH=".github/${WORKFLOW_PATH#*.github/}" # This extracts '.github/...'
WORKFLOW_URL="https://github.com/${REPO_PATH}/blob/${{ github.sha }}/${WORKFLOW_FILE_PATH}"
# Attempt to create a pull request via gh CLI, capture output even if it fails
PR_OUTPUT="$(gh pr create --title "Rust Crate Version Bump" \
--body "This PR is auto-generated by [GitHub Actions](${WORKFLOW_URL})." \
--base master --head rust-crate-version-bump-$SHORT_SHA \
--label "rust,automated pr,skip ci" \
--repo ${{ github.repository }} \
|| echo "${FAILURE_MESSAGE}")"
echo "PR output: $PR_OUTPUT"
# Check if PR creation was successful and proceed with auto-merge
if [[ "$PR_OUTPUT" != *"$FAILURE_MESSAGE" ]]; then
if ! gh pr merge --admin --squash --delete-branch $PR_OUTPUT; then
echo "Immediate merge with --admin failed, attempting auto-merge without --admin"
gh pr merge --auto --squash --delete-branch $PR_OUTPUT
fi
else
echo "Skipping auto-merge as PR creation failed"
exit 1
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}