Skip to content

Commit

Permalink
ci: parallelize publishing (#847)
Browse files Browse the repository at this point in the history
* ci: parallelize publishing

* ci: publish packages in parallel
  • Loading branch information
mrexox authored Oct 18, 2024
1 parent 9ddae47 commit ba633c0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 16 deletions.
93 changes: 82 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:
contents: write

jobs:
goreleaser:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -25,12 +25,6 @@ jobs:
with:
go-version-file: go.mod

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install --upgrade pip twine wheel setuptools

- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v2

Expand All @@ -49,22 +43,91 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}

- name: Publish to NPM, Rubygems and PyPI
- name: Preserve artifacts permissions with tar
run: tar -cvf dist.tar dist/
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist.tar

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags

- uses: actions/download-artifact@v4
with:
name: dist
- run: tar -xvf dist.tar

- name: Publish to NPM
env:
NPM_API_KEY: ${{ secrets.NPM_API_KEY }}
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
PYPI_API_KEY: ${{ secrets.PYPI_API_KEY }}
run: |
cat << EOF > ~/.npmrc
//registry.npmjs.org/:_authToken=${NPM_API_KEY}
EOF
chmod 0600 ~/.npmrc
cd packaging/
ruby pack.rb prepare
ruby pack.rb publish_npm
publish-gem:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags

- uses: actions/download-artifact@v4
with:
name: dist
- run: tar -xvf dist.tar

- name: Publish to Rubygems
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
mkdir -p ~/.gem/
cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
chmod 0600 ~/.gem/credentials
cd packaging/
ruby pack.rb prepare
ruby pack.rb publish_gem
publish-pypi:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags

- uses: actions/download-artifact@v4
with:
name: dist
- run: tar -xvf dist.tar

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install --upgrade pip twine wheel setuptools

- name: Publish to PyPI
env:
PYPI_API_KEY: ${{ secrets.PYPI_API_KEY }}
run: |
cat << EOF > ~/.pypirc
[distutils]
index-servers =
Expand All @@ -78,14 +141,22 @@ jobs:
chmod 0600 ~/.pypirc
cd packaging/
ruby pack.rb prepare
ruby pack.rb publish
ruby pack.rb publish_pypi
publish-homebrew:
needs: build
runs-on: ubuntu-latest
steps:
- name: Update Homebrew formula
uses: dawidd6/action-homebrew-bump-formula@v3
with:
formula: lefthook
token: ${{secrets.HOMEBREW_TOKEN}}

publish-winget:
needs: build
runs-on: ubuntu-latest
steps:
- name: Publish to Winget
uses: vedantmgoyal2009/winget-releaser@v2
with:
Expand Down
18 changes: 13 additions & 5 deletions packaging/pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ def put_binaries
end

def publish
puts "Publishing to PyPI..."
cd(File.join(__dir__, "pypi"))
system("python setup.py sdist bdist_wheel", exception: true)
system("python -m twine upload --verbose --repository lefthook dist/*", exception: true)
publish_pypi
publish_npm
publish_gem
end

def publish_npm
puts "Publishing lefthook npm..."
cd(File.join(__dir__, "npm"))
Dir["lefthook*"].each do |package|
Expand All @@ -143,13 +144,20 @@ def publish
puts "Publishing @evilmartians/lefthook-installer npm..."
cd(File.join(__dir__, "npm-installer"))
system("npm publish --access public", exception: true)
end

def publish_gem
puts "Publishing to Rubygems..."
cd(File.join(__dir__, "rubygems"))
system("rake build", exception: true)
system("gem push pkg/*.gem", exception: true)
end

puts "done"
def publish_pypi
puts "Publishing to PyPI..."
cd(File.join(__dir__, "pypi"))
system("python setup.py sdist bdist_wheel", exception: true)
system("python -m twine upload --verbose --repository lefthook dist/*", exception: true)
end

def replace_in_file(filepath, regexp, value)
Expand Down

0 comments on commit ba633c0

Please sign in to comment.