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 "actions@users.noreply.github.com" 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 }}