In a bolt action, the bolt is held fixed by its locking lugs, forcing all the expanding gas forward.
In a semi-automatic firearm, the bolt cycles back and forward between each shot, propelled by expanding gas (back) or the recoil spring (forward). When it moves forward, it strips a cartridge from the magazine and pushes it into the chamber. When it moves back, the extractor pulls the spent casing from the chamber. Once the case is clear of the chamber, the ejector kicks the case out of the weapon. The extractor and firing pin are often integral parts of the bolt.