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
| # This workflow will build a golang project and deploy the compiled binary to GitHub Pages | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
| name: Build and deploy undervolt-go | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write # to deploy to Pages | |
| id-token: write # to verify the deployment originates from an appropriate source | |
| jobs: | |
| # Build job | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Ensures full history, including tags | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.24.1' | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Prepare dependencies | |
| run: | | |
| go mod tidy # Ensures all required dependencies are installed | |
| echo "All required dependencies are installed" | |
| - name: Build undervolt-go | |
| run: | | |
| echo "Building undervolt-go..." | |
| go build -ldflags="-X 'main.version=$(git describe --tags)'" -o undervolt-go main.go # When building your application, pass the version from git tags using ldflags. | |
| echo "Build complete!" | |
| - name: Make compiled binary available | |
| run: | | |
| echo "Working on making the compiled binary available..." | |
| mkdir staging public | |
| cp -r ./undervolt-go ./staging/ # Copy the binary to the staging directory | |
| cp -r ./dist/script/* ./staging/ # Copy the install scripts to the staging directory | |
| echo "Ready to deploy!" | |
| - name: Compress the 'latest-build' under 'staging' directory and make it available in 'public' | |
| run: | | |
| zip -r undervolt-go.zip ./staging/ # Make a zip file of the latest build | |
| cp -r undervolt-go.zip ./public/ | |
| echo "Compress complete and available in public directory!" | |
| echo "Removing the now unused staging directory and undervolt-go.zip..." | |
| rm -r undervolt-go.zip staging | |
| echo "Removing complete!" | |
| - name: Output the files structure into a JSON file | |
| run: | | |
| # GitHub Actions' ubuntu-latest comes preinstalled with tree. So no need to install tree. | |
| #sudo apt update | |
| #sudo apt install -y tree | |
| tree -J public > files.json | |
| cp -r files.json ./public/ | |
| echo "JSON Manifest generated with the directory structure!" | |
| - name: Make web pages available | |
| run: | | |
| cp -r ./dist/pages/* ./public/ # Copy the web pages to the public directory | |
| - name: Upload artifact | |
| # upload artifact in the build stage, so that it is later on accessible in the deploy stage | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| # Upload entire repository | |
| path: './public' | |
| #- name: Test | |
| # run: go test -v ./... | |
| # Deploy job | |
| deploy: | |
| # Add a dependency to the build job | |
| needs: build | |
| # Deploy to the github-pages environment | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| # Specify runner + deployment step | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action |