Is there a way to create a tag `LastStable` to to main branch after it passed?

when the code has been merged to the master branch, circleci will be triggered and run.

Is there a way to create(or move) the git tag LastStable to the last commit and push the tag to github?

Here is the configration of my Rails project.

# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
  build:
    parallelism: 3
    working_directory: ~/workstream
    docker:
      # specify the version you desire here
      - image: circleci/ruby:2.6.6
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          PGHOST: 127.0.0.1
          PGUSER: root
          RAILS_ENV: test
      - image: circleci/postgres:9.6
        environment:
          POSTGRES_USER: root
          POSTGRES_DB: workstream_test
          POSTGRES_PASSWORD: test
      - image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
      - image: redis

    steps:
      - checkout
      - run: cp config/database.yml.example config/database.yml
      # - run: sudo chmod 777 /root/repo/vendor/bundle

      # Download and cache dependencies
      - restore_cache:
          key: workstream-{{ checksum "Gemfile.lock" }}

      - run:
          name: install dependencies
          command: |
            bundle install --jobs=4 --retry=3 --path vendor/bundle

      - save_cache:
          paths:
            - ./vendor/bundle
          key: workstream-{{ checksum "Gemfile.lock" }}

      # Database setup
#      - run: bundle exec rake db:create
      - run: bundle exec rake db:schema:load

      # run tests!
      - run:
          name: run tests
          command: |
            mkdir /tmp/test-results
            echo "=============================================="
            echo "Split test cases based on classname"
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=name)"

            echo "=============================================="
            echo "the following test files will be run on this container"
            echo $TEST_FILES | sed -e 'y/ /\n/;P;D'

            echo "=============================================="
            bundle exec rspec --profile 10 \
                              --format RspecJunitFormatter \
                              --out /tmp/test-results/rspec.xml \
                              --format progress \
                              $TEST_FILES

      # collect reports
      - store_test_results:
          path: /tmp/test-results
      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

@xiaoronglv, do you want to try adding these commands after your bundle command?

git tag LastBuild
git push origin --tags

as you can see, the parallelism is 3. All test cases will be dispatched to three parallel instances to run.

If I add your two lines after your bundle command, I assume it will be run when any instance pass the test, rather than all instance pass the test case.

for example, the following scenario scenario should not tag the commit.

instance 1 :white_check_mark: -> run your command
instance 2 :red_circle: - not run your command
instance 3 :white_check_mark: - run your command

@xiaoronglv, this looks promising: Collecting/combining files after parallel test runs – CircleCI Support Center

Use a workflow, then create a job which does the git tag in a fan-in step after the builds?

1 Like

As mentioned, make a workflow. In my experience, configurations with only one job quickly get out of hand, especially as you’re trying to use more advanced features like parallelism.

version: 2.0
jobs:
  build:
    <your existing job>
  publish:
    docker:
      - image: <something small with git>
    steps:
      - checkout
      - run:
          name: Tag "LastStable"
          command: |
            git tag LastStable
            git push origin --tags
workflows:
  build_and_publish:
    jobs:
      - build
      - publish:
          requires:
            - build
          filters:
            branches:
               only:
                 - <your mainline branch>