/stats README #62
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Release on Every Commit | |
| on: | |
| push: | |
| # This will trigger on every commit push on any branch. | |
| branches: | |
| - 'main' | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| # 1. Checkout the repository code. | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| # 2. Cache Cargo Registry. | |
| - name: Cache Cargo Registry | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/registry | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-registry- | |
| # 3. Cache Cargo Git Repositories. | |
| - name: Cache Cargo Git Repositories | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-git- | |
| # 4. Cache Build Artifacts (the target directory). | |
| - name: Cache Build Output | |
| uses: actions/cache@v3 | |
| with: | |
| path: target | |
| key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-target- | |
| - name: Test with Cargo | |
| run: cargo test | |
| # 5. Build your project with Cargo in release mode. | |
| - name: Build with Cargo | |
| run: cargo build --release | |
| # 6. Locate the compiled binary. | |
| - name: Locate Binary File | |
| id: locate_binary | |
| run: | | |
| # Adjust the binary name as needed. Here we assume the built binary is named "DynaRust" | |
| binary_path=$(find target/release -maxdepth 1 -type f -executable -name 'DynaRust*') | |
| if [ -z "$binary_path" ]; then | |
| echo "Binary file not found!" | |
| exit 1 | |
| else | |
| echo "Binary file found: ${binary_path}" | |
| echo "BINARY_PATH=${binary_path}" >> $GITHUB_ENV | |
| fi | |
| # 7. Determine the tag name. | |
| # If the push already is a tag push, respect that tag. | |
| # Otherwise, use the first 7 characters of the commit SHA prefixed with 'v'. | |
| - id: determine_tag | |
| name: Determine Tag Name | |
| shell: bash | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| TAG="${GITHUB_REF##*/}" | |
| echo "Running on tag push. Using tag: ${TAG}" | |
| else | |
| TAG="v${GITHUB_SHA:0:7}" | |
| echo "Not a tag push. Using commit SHA as tag: ${TAG}" | |
| fi | |
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | |
| # 8. Create a GitHub Release using the determined tag. | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.determine_tag.outputs.tag }} | |
| release_name: "Release ${{ steps.determine_tag.outputs.tag }}" | |
| draft: false | |
| prerelease: false | |
| # 9. Upload the built binary as a release asset. | |
| - name: Upload Release Asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ${{ env.BINARY_PATH }} | |
| asset_name: DynaRust | |
| asset_content_type: application/octet-stream |