Skip to content

gh workflow iteration #22

gh workflow iteration

gh workflow iteration #22

Workflow file for this run

name: build, test & publish on all platforms
on:
push:
tags:
- '*'
jobs:
verify-and-run:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all tags and history
- name: Get the latest commit SHA
id: get_sha
run: echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Debug - Print commit SHA
run: echo "Commit SHA - ${{ env.COMMIT_SHA }}"
- name: Check if commit is on main
id: check_main
run: |
# Fetch all branches to ensure we have the latest references
git fetch origin
# Check if the commit is in the main branch history
if git merge-base --is-ancestor ${{ env.COMMIT_SHA }} origin/main; then
echo "COMMIT_ON_MAIN=true" >> $GITHUB_ENV
else
echo "COMMIT_ON_MAIN=false" >> $GITHUB_ENV
fi
- name: Exit if not on main
if: env.COMMIT_ON_MAIN == 'false'
run: |
echo "This tag's commit is not on the main branch. Exiting workflow."
exit 1
- name: Verify and proceed
if: env.COMMIT_ON_MAIN == 'true'
run: echo "Tag is on main. Proceeding with the workflow..."
linux-x64:
needs: [verify-and-run]
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun install
- name: run tests
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun test --coverage
- name: build binary
run: |
cd /home/runner/work/gild-cli/gild-cli/main && bun run make
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_linux-x64
path: /home/runner/work/gild-cli/gild-cli/main/dist/gild
windows-x64:
needs: [verify-and-run]
runs-on: windows-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd D:/a/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd D:/a/gild-cli/gild-cli/main && bun test --coverage
- name: build binary
run: |
cd D:/a/gild-cli/gild-cli/main
bun run make
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_windows-x64
path: D:/a/gild-cli/gild-cli/main/dist/gild.exe
darwin-x64:
needs: [verify-and-run]
runs-on: macOS-13
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun test --coverage
- name: build binary # not using "make" script to be sure target is correct
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun build ./index.ts --compile --target=bun-darwin-x64 --outfile dist/gild
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_darwin-x64
path: /Users/runner/work/gild-cli/gild-cli/main/dist/gild
darwin-arm64:
needs: [verify-and-run]
runs-on: macOS-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: main
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: install dependencies
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun install
- name: run tests
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun test --coverage
- name: build binary # not using "make" script to be sure target is correct
run: |
cd /Users/runner/work/gild-cli/gild-cli/main
bun build ./index.ts --compile --target=bun-darwin-arm64 --outfile dist/gild
- name: upload to github releases
uses: actions/upload-artifact@v4
with:
name: gild-cli_${{ github.ref_name }}_darwin-arm64
path: /Users/runner/work/gild-cli/gild-cli/main/dist/gild
linux-x64-binary-test:
needs: [linux-x64]
runs-on: ubuntu-latest
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
darwin-x64-binary-test:
needs: [darwin-x64]
runs-on: macOS-13 # should default to x64, TODO: might need to specify target some how
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: uname -m
- name: Display structure of downloaded files
run: ls -R
darwin-arm64-binary-test:
needs: [darwin-arm64]
runs-on: macOS-latest # defaults to arm64 as of macOS14
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: uname -m
- name: Display structure of downloaded files
run: ls -R
windows-x64-binary-test:
needs: [windows-x64]
runs-on: windows-latest # defaults to 2022, TODO: might be worth tested 2019 also
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: confirm which arch
run: wmic cpu get DataWidth
- name: Display structure of downloaded files
run: Get-ChildItem -Recurse
binary-tests:
needs: [linux-x64-binary-test, darwin-x64-binary-test, darwin-arm64-binary-test, windows-x64-binary-test]
runs-on: ubuntu-latest
steps:
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
publish-gh-release-homebrew:
needs: [binary-tests]
runs-on: ubuntu-latest
steps:
- name: install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: download artifacts
uses: actions/download-artifact@v4
- name: release commit hash
run: echo ${{ github.sha }} > release.txt
- name: tarball for linux-x64
run: tar -czf gild-cli_${{ github.ref_name }}_linux-x64.tar.gz gild-cli_${{ github.ref_name }}_linux-x64/gild
- name: sha256 for linux-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_linux-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_linux-x64.txt
- name: tarball for darwin-arm64
run: tar -czf gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz gild-cli_${{ github.ref_name }}_darwin-arm64/gild
- name: sha256 for darwin-arm64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_darwin-arm64.txt
- name: tarball for darwin-x64
run: tar -czf gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz gild-cli_${{ github.ref_name }}_darwin-x64/gild
- name: sha256 for darwin-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_darwin-x64.txt
- name: tarball for windows-x64
run: tar -czf gild-cli_${{ github.ref_name }}_windows-x64.tar.gz gild-cli_${{ github.ref_name }}_windows-x64/gild.exe
- name: sha256 for windows-x64
run: shasum -a 256 gild-cli_${{ github.ref_name }}_windows-x64.tar.gz | awk '{print $1}' > gild-cli_${{ github.ref_name }}_windows-x64.txt
- name: release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ secrets.GH_TOKEN }}
files: |
gild-cli_${{ github.ref_name }}_darwin-arm64.tar.gz
gild-cli_${{ github.ref_name }}_darwin-arm64.txt
gild-cli_${{ github.ref_name }}_darwin-x64.tar.gz
gild-cli_${{ github.ref_name }}_darwin-x64.txt
gild-cli_${{ github.ref_name }}_linux-x64.tar.gz
gild-cli_${{ github.ref_name }}_linux-x64.txt
gild-cli_${{ github.ref_name }}_windows-x64.tar.gz
gild-cli_${{ github.ref_name }}_windows-x64.txt
- name: Compute and export SHA256 hashes
id: compute_hashes
run: |
# Define your targets
targets=("linux-x64" "darwin-x64" "darwin-arm64")
# Loop through each target
for target in "${targets[@]}"; do
# Compute SHA-256 hash for each target file
hash=$(shasum -a 256 "gild-cli_${{ github.ref_name }}_${target}.tar.gz" | awk '{print $1}')
# Set the environment variable
echo "${target^^}_SHA256=$hash" >> $GITHUB_ENV
done
- name: Use SHA256 Variables
run: |
# Example of using the exported environment variables
echo "Linux x64 SHA256: $LINUX_X64_SHA256"
echo "macOS x64 SHA256: $DARWIN_X64_SHA256"
echo "macoS arm64 SHA256: $DARWIN_ARM64_SHA256"
- name: checkout homebrew repo
uses: actions/checkout@v4
with:
repository: samifouad/homebrew-gild
token: ${{ secrets.GH_TOKEN }}
ref: main
path: homebrew-gild
- name: checkout gild-cli repo
uses: actions/checkout@v4
with:
path: gild-cli
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
run: sudo apt-get install -y jq
- name: Update JSON file
run: |
# Use jq to update or create JSON file
echo '{}' | jq \
--arg linux_x64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_linux_x64.tar.gz" \
--arg linux_x64_hash "${{ env.LINUX-X64_SHA256 }}" \
--arg darwin_arm64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_darwin_arm64.tar.gz" \
--arg darwin_arm64_hash "${{ env.DARWIN-ARM64_SHA256 }}" \
--arg darwin_x64_url "https://github.com/samifouad/gild-cli/releases/download/${{ github.ref_name }}/gild_cli_${{ github.ref_name }}_darwin_x64.tar.gz" \
--arg darwin_x64_hash "${{ env.DARWIN-X64_SHA256 }}" \
--arg version "${{ github.ref_name }}" \
'. + {
linux_x64_url: $linux_x64_url,
linux_x64_hash: $linux_x64_hash,
darwin_arm64_url: $darwin_arm64_url,
darwin_arm64_hash: $darwin_arm64_hash,
darwin_x64_url: $darwin_x64_url,
darwin_x64_hash: $darwin_x64_hash,
version: $version
}' > homebrew.json
- name: verify homebrew.json
run: |
cat homebrew.json
- name: move homebrew.ts
run: |
mv gild-cli/homebrew.ts homebrew.ts
ls -R
- name: run homebrew.ts & print output
run: |
bun run homebrew.ts
cat homebrew-gild/Formula/gild.rb
- name: Set up SSH
env:
RSA_PRIVATE_KEY: ${{ secrets.SIGNING_KEY }}
run: |
echo "$RSA_PRIVATE_KEY" > /tmp/id_rsa
chmod 600 /tmp/id_rsa
eval "$(ssh-agent -s)"
ssh-add /tmp/id_rsa
- name: push changes to homebrew repo
run: |
cd homebrew-gild
git config --global user.email "[email protected]"
git config --global user.name "Sami Fouad"
git config --global gpg.format ssh
git config --global commit.gpgsign true
git config --global tag.gpgSign true
git config --global user.signingkey /tmp/id_rsa
git add .
git commit -m 'automated version bump'
git tag ${{ github.ref_name }} -m 'automated version bump to ${{ github.ref_name }}'
git push --follow-tags
- name: stop action
run: |
exit 1
publish-linux-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: checkout code
uses: actions/checkout@v4
- name: download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare linux-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-linux-x64/package.json > npm/gild-linux-x64/package.tmp.json && mv npm/gild-linux-x64/package.tmp.json npm/gild-linux-x64/package.json
cp ./gild-cli_${{ env.CURRENT_TAG }}_linux-x64/gild npm/gild-linux-x64/gild
- name: configure npm & publish
run: |
cd npm/gild-linux-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-windows-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
# - name: Display structure of downloaded files
# run: dir /s
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-windows-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-windows-x64/package.json > npm/gild-windows-x64/package.tmp.json && mv npm/gild-windows-x64/package.tmp.json npm/gild-windows-x64/package.json
cp gild-cli_${{ env.CURRENT_TAG }}_windows-x64/gild.exe npm/gild-windows-x64/gild.exe
- name: Configure npm & publish
run: |
cd npm/gild-windows-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-darwin-x64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-darwin-x64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-darwin-x64/package.json > npm/gild-darwin-x64/package.tmp.json && mv npm/gild-darwin-x64/package.tmp.json npm/gild-darwin-x64/package.json
cp ./gild-cli_${{ env.CURRENT_TAG }}_darwin-x64/gild npm/gild-darwin-x64/gild
- name: Configure npm & publish
run: |
cd npm/gild-darwin-x64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-darwin-arm64-to-npm:
needs: [publish-gh-release-homebrew]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare gild-darwin-arm64's package.json and copy binary artifact
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild-darwin-arm64/package.json > npm/gild-darwin-arm64/package.tmp.json && mv npm/gild-darwin-arm64/package.tmp.json npm/gild-darwin-arm64/package.json
cp gild-cli_${{ env.CURRENT_TAG }}_darwin-arm64/gild npm/gild-darwin-arm64/gild
- name: Configure npm & publish
run: |
cd npm/gild-darwin-arm64
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-main-to-npm:
needs: [publish-windows-x64-to-npm, publish-linux-x64-to-npm, publish-darwin-x64-to-npm, publish-darwin-arm64-to-npm]
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Install jq
shell: bash
run: |
sudo apt-get install jq -y
- name: Prepare package.json
shell: bash
run: |
jq ". + {version: \"${{ env.CURRENT_TAG }}\"}" npm/gild/package.json > npm/gild/package.tmp.json && mv npm/gild/package.tmp.json npm/gild/package.json
- name: Configure npm & publish
run: |
cd npm/gild
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > .npmrc
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}