|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' # Trigger on version tags like v1.0.0, v0.1.0, etc. |
| 7 | + workflow_dispatch: # Allow manual triggers |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write # Required for creating releases |
| 11 | + packages: write # Required for pushing to GHCR |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-release: |
| 15 | + name: Build and Release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: '22' |
| 26 | + cache: 'npm' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: npm ci |
| 30 | + |
| 31 | + - name: Build TypeScript |
| 32 | + run: npm run build |
| 33 | + |
| 34 | + - name: Extract version from tag |
| 35 | + id: version_early |
| 36 | + run: | |
| 37 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 38 | + VERSION=$(node -p "require('./package.json').version") |
| 39 | + echo "version=v$VERSION" >> $GITHUB_OUTPUT |
| 40 | + echo "version_number=$VERSION" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 43 | + VERSION_NUMBER="${VERSION#v}" |
| 44 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | + echo "version_number=$VERSION_NUMBER" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Log in to GitHub Container Registry |
| 49 | + uses: docker/login-action@v3 |
| 50 | + with: |
| 51 | + registry: ghcr.io |
| 52 | + username: ${{ github.actor }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@v3 |
| 57 | + |
| 58 | + - name: Build and push Squid image |
| 59 | + uses: docker/build-push-action@v5 |
| 60 | + with: |
| 61 | + context: ./containers/squid |
| 62 | + push: true |
| 63 | + tags: | |
| 64 | + ghcr.io/${{ github.repository }}/squid:${{ steps.version_early.outputs.version_number }} |
| 65 | + ghcr.io/${{ github.repository }}/squid:latest |
| 66 | + cache-from: type=gha |
| 67 | + cache-to: type=gha,mode=max |
| 68 | + |
| 69 | + - name: Build and push Copilot image |
| 70 | + uses: docker/build-push-action@v5 |
| 71 | + with: |
| 72 | + context: ./containers/copilot |
| 73 | + push: true |
| 74 | + tags: | |
| 75 | + ghcr.io/${{ github.repository }}/copilot:${{ steps.version_early.outputs.version_number }} |
| 76 | + ghcr.io/${{ github.repository }}/copilot:latest |
| 77 | + cache-from: type=gha |
| 78 | + cache-to: type=gha,mode=max |
| 79 | + |
| 80 | + - name: Install pkg for binary creation |
| 81 | + run: npm install -g pkg |
| 82 | + |
| 83 | + - name: Create binaries |
| 84 | + run: | |
| 85 | + mkdir -p release |
| 86 | +
|
| 87 | + # Create standalone executable for Linux |
| 88 | + pkg . \ |
| 89 | + --targets node18-linux-x64 \ |
| 90 | + --output release/awf |
| 91 | +
|
| 92 | + # Rename output to include platform |
| 93 | + mv release/awf-linux release/awf-linux-x64 |
| 94 | +
|
| 95 | + - name: Create tarball for npm package |
| 96 | + run: | |
| 97 | + npm pack |
| 98 | + mv *.tgz release/awf.tgz |
| 99 | +
|
| 100 | + - name: Generate checksums |
| 101 | + run: | |
| 102 | + cd release |
| 103 | + sha256sum * > checksums.txt |
| 104 | +
|
| 105 | + - name: Create Release Notes |
| 106 | + id: release_notes |
| 107 | + run: | |
| 108 | + cat > release_notes.md << 'EOF' |
| 109 | + ## Installation |
| 110 | +
|
| 111 | + ### Binary Installation (Recommended) |
| 112 | +
|
| 113 | + **Linux (x64):** |
| 114 | + ```bash |
| 115 | + curl -L https://github.com/${{ github.repository }}/releases/download/${{ steps.version_early.outputs.version }}/awf-linux-x64 -o awf |
| 116 | + chmod +x awf |
| 117 | + sudo mv awf /usr/local/bin/ |
| 118 | + ``` |
| 119 | +
|
| 120 | + ### NPM Installation (Alternative) |
| 121 | +
|
| 122 | + ```bash |
| 123 | + # Install from tarball |
| 124 | + npm install -g https://github.com/${{ github.repository }}/releases/download/${{ steps.version_early.outputs.version }}/awf.tgz |
| 125 | + ``` |
| 126 | +
|
| 127 | + ### Requirements |
| 128 | +
|
| 129 | + - Docker and Docker Compose must be installed |
| 130 | + - For iptables manipulation, run with sudo: `sudo awf ...` |
| 131 | + - Container images will be pulled automatically from GHCR on first run |
| 132 | +
|
| 133 | + ## Verification |
| 134 | +
|
| 135 | + Verify checksums after download: |
| 136 | + ```bash |
| 137 | + sha256sum -c checksums.txt |
| 138 | + ``` |
| 139 | +
|
| 140 | + ## Usage |
| 141 | +
|
| 142 | + ```bash |
| 143 | + sudo awf --allow-domains github.com,api.github.com 'curl https://api.github.com' |
| 144 | + ``` |
| 145 | +
|
| 146 | + See [README.md](https://github.com/${{ github.repository }}/blob/${{ steps.version_early.outputs.version }}/README.md) for full documentation. |
| 147 | +
|
| 148 | + ## Container Images |
| 149 | +
|
| 150 | + Published to GitHub Container Registry: |
| 151 | + - `ghcr.io/${{ github.repository }}/squid:${{ steps.version_early.outputs.version_number }}` |
| 152 | + - `ghcr.io/${{ github.repository }}/copilot:${{ steps.version_early.outputs.version_number }}` |
| 153 | + - `ghcr.io/${{ github.repository }}/squid:latest` |
| 154 | + - `ghcr.io/${{ github.repository }}/copilot:latest` |
| 155 | + EOF |
| 156 | +
|
| 157 | + - name: Create GitHub Release |
| 158 | + uses: softprops/action-gh-release@v1 |
| 159 | + with: |
| 160 | + tag_name: ${{ steps.version_early.outputs.version }} |
| 161 | + name: Release ${{ steps.version_early.outputs.version }} |
| 162 | + body_path: release_notes.md |
| 163 | + draft: false |
| 164 | + prerelease: ${{ contains(steps.version_early.outputs.version, 'alpha') || contains(steps.version_early.outputs.version, 'beta') || contains(steps.version_early.outputs.version, 'rc') }} |
| 165 | + files: | |
| 166 | + release/awf-linux-x64 |
| 167 | + release/awf.tgz |
| 168 | + release/checksums.txt |
| 169 | + env: |
| 170 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + |
| 172 | + - name: Upload artifacts (for debugging) |
| 173 | + uses: actions/upload-artifact@v4 |
| 174 | + if: always() |
| 175 | + with: |
| 176 | + name: release-artifacts |
| 177 | + path: release/ |
| 178 | + retention-days: 7 |
0 commit comments