[WIP] updates github action #18
This file contains 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
name: Go | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.20' # specify the Go version | |
- name: Build | |
run: go build -v ./... | |
- name: Test | |
run: go test -v ./... | |
- name: Build Binary for Linux | |
run: GOOS=linux GOARCH=amd64 go build -o wp-wingman main.go | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Get latest release | |
id: latest_release | |
run: | | |
LATEST_RELEASE=$(curl --silent -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r .upload_url | cut -d "{" -f 1) | |
echo "::set-output name=upload_url::$LATEST_RELEASE" | |
- name: Get asset ID | |
id: get_asset_id | |
run: | | |
RELEASE_ID=$(echo "${{ steps.latest_release.outputs.upload_url }}" | sed -r "s/.*\/releases\/([0-9]+)\/assets/\1/") | |
ASSET_ID=$(curl --silent -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" | jq '.[] | select(.name=="wp-wingman") | .id') | |
echo "::set-output name=asset_id::$ASSET_ID" | |
- name: Delete existing asset | |
run: | | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/assets/${{ steps.get_asset_id.outputs.asset_id }}" | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.latest_release.outputs.upload_url }} | |
asset_path: ./wp-wingman | |
asset_name: wp-wingman | |
asset_content_type: application/octet-stream |