diff --git a/.github/actions/commit_and_push/action.yml b/.github/actions/commit_and_push/action.yml new file mode 100644 index 0000000000..41c7589529 --- /dev/null +++ b/.github/actions/commit_and_push/action.yml @@ -0,0 +1,33 @@ +name: Commit and Push Changes +description: 'Configures git, commits changes and pushes to a new branch' +inputs: + branch-name: + description: 'Name of the branch to create' + required: true + commit-message: + description: 'Commit message' + required: true + gpg_signing_key: + description: 'The GPG signing key to use for signing commits' + required: true +runs: + using: composite + steps: + - uses: ./.github/actions/configure_git + with: + gpg_signing_key: ${{ inputs.gpg_signing_key }} + + - name: Commit and push changes + shell: bash + run: | + # Create and switch to new branch + git switch -c "${{ inputs.branch-name }}" + + # Add and commit changes if there are any + git add --all + if ! git diff --cached --quiet; then + git commit -m "${{ inputs.commit-message }}" + git push origin "${{ inputs.branch-name }}" + else + echo "No changes to commit. Skipping commit and push." + fi diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d382a042aa..7387e80a57 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -98,25 +98,25 @@ jobs: EXCLUDE_DIRS=$(echo $EXCLUDE_DIRS | xargs) echo "exclude-dirs=$EXCLUDE_DIRS" >> $GITHUB_OUTPUT - get-version: - name: Get Azle Version + create-branch-prefix: + name: Create Branch Prefix runs-on: ubuntu-latest outputs: - azle-version: ${{ steps.get-version.outputs.azle-version }} + branch-prefix: ${{ steps.create-prefix.outputs.branch-prefix }} steps: - uses: actions/checkout@v4 - - id: get-version + - id: create-prefix run: | VERSION=$(jq -r '.version' package.json) - echo "azle-version=$VERSION" >> $GITHUB_OUTPUT + echo "branch-prefix=benchmark--$VERSION-" >> $GITHUB_OUTPUT run-benchmarks: name: ${{ matrix.benchmark_group.name }} needs: - determine-should-run-benchmarks - set-exclude-dirs - - get-version + - create-branch-prefix if: ${{ needs.determine-should-run-benchmarks.outputs.should-run-benchmarks == 'true' }} strategy: fail-fast: false @@ -155,14 +155,14 @@ jobs: with: directories: ${{ matrix.benchmark_group.directories }} exclude-dirs: ${{ needs.set-exclude-dirs.outputs.exclude-dirs }} - azle-version: ${{ needs.get-version.outputs.azle-version }} + branch-prefix: ${{ needs.create-branch-prefix.outputs.branch-prefix }} finalize-benchmark: - needs: [run-benchmarks, get-version] + needs: [run-benchmarks, create-branch-prefix] uses: ./.github/workflows/finalize_changes.yml with: - branch-prefix: 'benchmark--${{ needs.get-version.outputs.azle-version }}-' - commit-message: 'Update all dependencies for benchmark ${{ needs.get-version.outputs.azle-version }}' + branch-prefix: ${{ needs.create-branch-prefix.outputs.branch-prefix }} + commit-message: 'Update all dependencies for benchmark' secrets: GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/benchmark_parallel.yml b/.github/workflows/benchmark_parallel.yml index 6b68b93bdb..6a9a0b097d 100644 --- a/.github/workflows/benchmark_parallel.yml +++ b/.github/workflows/benchmark_parallel.yml @@ -9,7 +9,7 @@ on: required: false type: string default: '' - azle-version: + branch-prefix: required: true type: string @@ -25,11 +25,7 @@ jobs: prepare-benchmark: name: Prepare Benchmark runs-on: ubuntu-latest - env: - GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} # All commits must be verified - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} outputs: - azle-version: ${{ inputs.azle-version }} test-infos: ${{ steps.get-test-infos.outputs.test-infos }} steps: - uses: actions/checkout@v4 @@ -71,23 +67,33 @@ jobs: working-directory: ${{ matrix.test.path }} run: dfx start --clean --background --host 127.0.0.1:8000 --artificial-delay 0 + - name: Print benchmark.md contents (before test) + working-directory: ${{ matrix.test.path }} + run: | + if [ -f benchmark.md ]; then + echo "Contents of benchmark.md before test:" + cat benchmark.md + else + echo "benchmark.md does not exist before test" + fi + - name: Run npm test (continue on error) working-directory: ${{ matrix.test.path }} continue-on-error: true run: npm test - - uses: ./.github/actions/configure_git - with: - gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }} - - - name: Commit and push changes + - name: Print benchmark.md contents (after test) + working-directory: ${{ matrix.test.path }} run: | - BRANCH_NAME="benchmark--${{ needs.prepare-benchmark.outputs.azle-version }}-$(echo '${{ matrix.test.displayPath }}' | sed 's/\//-/g')" - git switch -c "$BRANCH_NAME" - git add --all - if ! git diff --cached --quiet; then - git commit -m "Run benchmarks for ${{ matrix.test.displayPath }}" + if [ -f benchmark.md ]; then + echo "Contents of benchmark.md after test:" + cat benchmark.md else - echo "No changes to commit. Skipping commit and push." + echo "benchmark.md does not exist after test" fi - git push origin "$BRANCH_NAME" + + - uses: ./.github/actions/commit_and_push + with: + branch-name: "${{ inputs.branch-prefix }}$(echo '${{ matrix.test.displayPath }}' | sed 's/\//-/g')" + commit-message: 'Run benchmarks for ${{ matrix.test.displayPath }}' + gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }} diff --git a/.github/workflows/release_parallel.yml b/.github/workflows/release_parallel.yml index b4169f00f2..026570e390 100644 --- a/.github/workflows/release_parallel.yml +++ b/.github/workflows/release_parallel.yml @@ -111,22 +111,12 @@ jobs: continue-on-error: true run: npm test - - uses: ./.github/actions/configure_git + - uses: ./.github/actions/commit_and_push with: + branch-name: "update--${{ needs.prepare-release.outputs.release-version }}-$(echo '${{ matrix.test.displayPath }}' | sed 's/\//-/g')" + commit-message: 'Update dependencies for ${{ matrix.test.displayPath }}' gpg_signing_key: ${{ secrets.GPG_SIGNING_KEY }} - - name: Commit and push changes - run: | - BRANCH_NAME="update--${{ needs.prepare-release.outputs.release-version }}-$(echo '${{ matrix.test.displayPath }}' | sed 's/\//-/g')" - git switch -c "$BRANCH_NAME" - git add --all - if ! git diff --cached --quiet; then - git commit -m "Update dependencies for ${{ matrix.test.displayPath }}" - else - echo "No changes to commit. Skipping commit and push." - fi - git push origin "$BRANCH_NAME" - finalize-release: needs: [prepare-release, update-test-files-for-release-commit] uses: ./.github/workflows/finalize_changes.yml