Switch to Trusted Publishing. #316
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: [push, pull_request] | |
name: Build & publish | |
jobs: | |
build: | |
if: ${{ !contains(github.event.head_commit.message, 'skip ci') }} | |
runs-on: ubuntu-latest | |
env: | |
RELEASE_BRANCH: ${{ startsWith(github.event.ref, 'refs/heads/develop-') || startsWith(github.event.ref, 'refs/heads/release-') }} | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
submodules: true | |
- name: Install dependencies | |
run: sudo apt-get install ccache | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
- name: Set up caching | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ccache | |
key: openFPGALoader-${{ hashFiles('emsdk', 'zlib-src', 'libusb-src', 'libftdi-src', 'hidapi-src', 'openFPGALoader-src', 'build.sh') }} | |
restore-keys: | | |
openFPGALoader-${{ hashFiles('emsdk', 'zlib-src', 'libusb-src', 'libftdi-src', 'hidapi-src', 'openFPGALoader-src', 'build.sh') }} | |
openFPGALoader- | |
- name: Set up ccache | |
run: | | |
ccache --max-size=2G -z | |
- name: Build openFPGALoader | |
run: | | |
./build.sh | |
- name: Build NPM package | |
run: | | |
./package.sh | |
- name: Upload NPM package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: npmjs/dist/ | |
- name: Print ccache statistics | |
run: | | |
ccache -s | |
check: # group all `test (*)` workflows into one for the required status check | |
needs: [build] | |
if: ${{ always() && !contains(needs.*.result, 'cancelled') }} | |
runs-on: ubuntu-latest | |
steps: | |
- run: ${{ contains(needs.*.result, 'failure') && 'false' || 'true' }} | |
publish: | |
needs: check | |
runs-on: ubuntu-latest | |
environment: publish | |
permissions: | |
id-token: write | |
if: ${{ !contains(github.event.head_commit.message, 'skip js') }} | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Update npm | |
run: npm install -g npm@latest | |
- name: Download NPM package | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
- name: Publish package to NPM (dry run) | |
if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/heads/develop') }} | |
run: npm publish $(find dist -name *.tgz -printf 'file:%p ') --tag latest --dry-run | |
- name: Publish package to NPM | |
if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/heads/release') }} | |
run: npm publish $(find dist -name *.tgz -printf 'file:%p ') --tag latest | |
release: | |
needs: check | |
runs-on: ubuntu-latest | |
if: ${{ contains(github.event.head_commit.message, 'autorelease') && github.event_name == 'push' && startsWith(github.event.ref, 'refs/heads/develop') }} | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PUSH_TOKEN }} | |
- name: Update release branch | |
run: | | |
release_branch=${{ github.event.ref }} | |
release_branch=${release_branch/develop/release} | |
git push origin HEAD:${release_branch} |