| 1 |
name: Publish |
| 2 |
|
| 3 |
on: |
| 4 |
release: |
| 5 |
types: [published] |
| 6 |
|
| 7 |
|
| 8 |
jobs: |
| 9 |
publish-rust-crate: |
| 10 |
runs-on: ubuntu-latest |
| 11 |
steps: |
| 12 |
- uses: actions/checkout@v4 |
| 13 |
- name: Login to crates.io |
| 14 |
run: cargo login $CRATES_IO_TOKEN |
| 15 |
env: |
| 16 |
CRATES_IO_TOKEN: ${{ secrets.crates_io_token }} |
| 17 |
- name: Dry run publish |
| 18 |
run: cargo publish --dry-run --manifest-path fiat-rust/Cargo.toml |
| 19 |
- name: Publish |
| 20 |
run: cargo publish --manifest-path fiat-rust/Cargo.toml |
| 21 |
env: |
| 22 |
CARGO_REGISTRY_TOKEN: ${{ secrets.crates_io_token }} |
| 23 |
|
| 24 |
bump-rust-crate-version: |
| 25 |
runs-on: ubuntu-latest |
| 26 |
permissions: |
| 27 |
contents: write |
| 28 |
pull-requests: write |
| 29 |
steps: |
| 30 |
- uses: actions/checkout@v4 |
| 31 |
- name: Bump Rust crate version |
| 32 |
id: bumpRustViaPush |
| 33 |
run: | |
| 34 |
etc/ci/bump-fiat-rust-crate-version.sh |
| 35 |
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" |
| 36 |
git config http.sslVerify false |
| 37 |
git config user.name "Automated Publisher" |
| 38 |
git config user.email "[email protected]" |
| 39 |
git remote add publisher "${remote_repo}" |
| 40 |
git remote update |
| 41 |
git show-ref # useful for debugging |
| 42 |
git branch --verbose |
| 43 |
|
| 44 |
git checkout -b temp |
| 45 |
git branch -D master || true |
| 46 |
git checkout -b master publisher/master |
| 47 |
git add fiat-rust/Cargo.toml |
| 48 |
timestamp=$(date -u) |
| 49 |
git commit -m "Automated Rust Crate Version Bump: ${timestamp} ${GITHUB_SHA}" |
| 50 |
if git push publisher master; then |
| 51 |
echo "Push successful" |
| 52 |
else |
| 53 |
# If the push fails, get the short SHA of the latest commit |
| 54 |
SHORT_SHA=$(git rev-parse --short HEAD) |
| 55 |
# Create and push to a new branch |
| 56 |
git checkout -b rust-crate-version-bump-$SHORT_SHA |
| 57 |
git push --set-upstream publisher rust-crate-version-bump-$SHORT_SHA |
| 58 |
FAILURE_MESSAGE="PR creation failed" |
| 59 |
# Locate workflow file, remove the Git ref at the end |
| 60 |
WORKFLOW_PATH="${GITHUB_WORKFLOW_REF%@*}" |
| 61 |
# Split the string to insert the blob/SHA part correctly |
| 62 |
REPO_PATH="${WORKFLOW_PATH%/.github/*}" # This extracts 'everything before /.github/' |
| 63 |
WORKFLOW_FILE_PATH=".github/${WORKFLOW_PATH#*.github/}" # This extracts '.github/...' |
| 64 |
WORKFLOW_URL="https://github.com/${REPO_PATH}/blob/${{ github.sha }}/${WORKFLOW_FILE_PATH}" |
| 65 |
# Attempt to create a pull request via gh CLI, capture output even if it fails |
| 66 |
PR_OUTPUT="$(gh pr create --title "Rust Crate Version Bump" \ |
| 67 |
--body "This PR is auto-generated by [GitHub Actions](${WORKFLOW_URL})." \ |
| 68 |
--base master --head rust-crate-version-bump-$SHORT_SHA \ |
| 69 |
--label "rust,automated pr,skip ci" \ |
| 70 |
--repo ${{ github.repository }} \ |
| 71 |
|| echo "${FAILURE_MESSAGE}")" |
| 72 |
echo "PR output: $PR_OUTPUT" |
| 73 |
# Check if PR creation was successful and proceed with auto-merge |
| 74 |
if [[ "$PR_OUTPUT" != *"$FAILURE_MESSAGE" ]]; then |
| 75 |
if ! gh pr merge --admin --squash --delete-branch $PR_OUTPUT; then |
| 76 |
echo "Immediate merge with --admin failed, attempting auto-merge without --admin" |
| 77 |
gh pr merge --auto --squash --delete-branch $PR_OUTPUT |
| 78 |
fi |
| 79 |
else |
| 80 |
echo "Skipping auto-merge as PR creation failed" |
| 81 |
exit 1 |
| 82 |
fi |
| 83 |
fi |
| 84 |
env: |
| 85 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |