Delete tag correctly #130
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: Build Go Binary | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
jobs: | |
check_changes: | |
outputs: | |
run_build: ${{ steps.verify-changed-files.outputs.any_changed }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verify Changed files | |
uses: tj-actions/changed-files@v41 | |
id: verify-changed-files | |
with: | |
files: | | |
src/** | |
.github/workflows/go.yml | |
create_release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
needs: check_changes | |
if: needs.check_changes.outputs.run_build == 'true' | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
new_version: ${{ steps.semver.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: paulhatch/semantic-version@v5.3.0 | |
id: semver | |
with: | |
# The prefix to use to identify tags | |
tag_prefix: "v" | |
# A string which, if present in a git commit, indicates that a change represents a | |
# major (breaking) change, supports regular expressions wrapped with '/' | |
major_pattern: "(MAJOR)" | |
# A string which indicates the flags used by the `major_pattern` regular expression. Supported flags: idgs | |
major_regexp_flags: "" | |
# Same as above except indicating a minor change, supports regular expressions wrapped with '/' | |
minor_pattern: "(MINOR)" | |
# A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs | |
minor_regexp_flags: "" | |
# A string to determine the format of the version output | |
version_format: "${major}.${minor}.${patch}" | |
bump_each_commit: false | |
- name: Create Release | |
uses: "marvinpinto/action-automatic-releases@latest" | |
id: create_release | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
title: "Release ${{ steps.semver.outputs.version_tag }}" | |
automatic_release_tag: "${{ steps.semver.outputs.version_tag }}" | |
prerelease: false | |
draft: true | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
needs: [check_changes, create_release] | |
if: needs.check_changes.outputs.run_build == 'true' | |
strategy: | |
matrix: | |
os: [linux, windows, darwin] | |
go: [1.21.3] | |
arch: [amd64, arm64] | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Update version | |
run: | | |
sed -i'' -e 's/Version:[[:space:]]*"[0-9]\+\.[0-9]\+\.[0-9]\+"/Version: "${{ needs.create_release.outputs.new_version }}"/g' ./src/main.go | |
- name: Get dependencies | |
run: cd ./src && go get -v -t -d ./... | |
- name: Build | |
env: | |
GOARCH: ${{ matrix.arch }} | |
GOOS: ${{ matrix.os }} | |
run: go build -v -ldflags="-s -w -extldflags \"-static\"" ./src | |
- name: Build for Android arm64 (Special Case) | |
if: matrix.os == 'linux' && matrix.arch == 'arm64' | |
env: | |
GOOS: android | |
GOARCH: arm64 | |
run: go build -v -o CaffeineC-Android-arm64 ./src | |
- name: upload artifact | |
uses: actions/upload-release-asset@v1.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_release.outputs.upload_url }} | |
asset_path: ${{ matrix.os == 'windows' && './CaffeineC.exe' || './CaffeineC' }} | |
asset_name: "CaffeineC-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}" | |
asset_content_type: application/octet-stream | |
- name: Set distribution | |
id: set-distribution | |
if: matrix.os == 'linux' | |
run: | | |
echo "distribution=$(lsb_release -cs)" >> $GITHUB_ENV | |
- name: Prepare files for Debian package | |
if: matrix.os == 'linux' | |
run: | | |
mkdir -p .debpkg/usr/local/bin | |
cp ./CaffeineC .debpkg/usr/local/bin/CaffeineC | |
- name: Build Debian package and upload (Linux only) | |
if: matrix.os == 'linux' | |
uses: jiro4989/build-deb-action@v3 | |
id: build-deb | |
with: | |
package: caffeinec | |
package_root: .debpkg | |
maintainer: vyPal <kubik.palacky@gmail.com> | |
version: ${{ needs.create_release.outputs.new_version }} | |
arch: ${{ matrix.arch }} | |
desc: The CaffeineC compiler | |
- name: Upload Debian package | |
if: matrix.os == 'linux' | |
run: | | |
curl --user ${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_PASSWORD }} \ | |
--upload-file ${{ steps.build-deb.outputs.file_name }} \ | |
https://src.vypal.me/api/packages/vypal/debian/pool/${{ env.distribution }}/main/upload | |
- name: Prepare files for RPM package | |
if: matrix.os == 'linux' | |
run: | | |
mkdir -p .rpmpkg/usr/local/bin | |
cp ./CaffeineC .rpmpkg/usr/local/bin/CaffeineC | |
- name: Build RPM package and upload (Linux only) | |
if: matrix.os == 'linux' && matrix.arch == 'amd64' | |
uses: jiro4989/build-rpm-action@v2 | |
id: build-rpm | |
with: | |
package: CaffeineC | |
package_root: .rpmpkg | |
maintainer: vyPal <kubik.palacky@gmail.com> | |
version: ${{ needs.create_release.outputs.new_version }} | |
arch: x86_64 | |
summary: The CaffeineC compiler | |
desc: The CaffeineC compiler | |
license: GPL | |
- name: Sign RPM | |
if: matrix.os == 'linux' && matrix.arch == 'amd64' | |
run: | | |
sudo apt-get install -y rpm expect | |
echo "${{ secrets.RPM_SIGNING_KEY }}" | gpg --batch --yes --import | |
sudo chown runner:runner ${{ steps.build-rpm.outputs.file_name }} | |
expect -c " | |
spawn rpmsign --addsign --key-id ${{ secrets.KEY_ID }} ${{ steps.build-rpm.outputs.file_name }} | |
expect -exact \"Enter pass phrase: \" | |
send -- \"${{ secrets.KEY_PASSPHRASE }}\r\" | |
expect eof | |
" | |
- name: Upload RPM package | |
if: matrix.os == 'linux' && matrix.arch == 'amd64' | |
run: | | |
curl --user ${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_PASSWORD }} \ | |
--upload-file ${{ steps.build-rpm.outputs.file_name }} \ | |
https://src.vypal.me/api/packages/vypal/rpm/upload | |
- name: Upload artifact for Android arm64 (Special Case) | |
if: matrix.os == 'linux' && matrix.arch == 'arm64' | |
uses: actions/upload-release-asset@v1.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_release.outputs.upload_url }} | |
asset_path: CaffeineC-Android-arm64 | |
asset_name: "CaffeineC-Android-arm64" | |
asset_content_type: application/octet-stream | |
update_version: | |
name: Update versions | |
runs-on: ubuntu-latest | |
needs: [check_changes, create_release, build] | |
if: needs.check_changes.outputs.run_build == 'true' | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Update version | |
run: | | |
sed -i 's/Version:[[:space:]]*"[0-9]\+\.[0-9]\+\.[0-9]\+"/Version: "${{ needs.create_release.outputs.new_version }}"/g' ./src/main.go | |
- name: Commit and push | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add ./src/main.go | |
git add ./src/go.mod | |
git add ./src/go.sum | |
git commit -m "Update version to ${{ needs.create_release.outputs.new_version }}" | |
git push | |
finalize_release: | |
name: Finalize Release | |
runs-on: ubuntu-latest | |
needs: [check_changes, create_release, build] | |
if: always() && needs.check_changes.outputs.run_build == 'true' | |
steps: | |
- name: Get release ID | |
id: get_release_id | |
run: | | |
UPLOAD_URL="${{ needs.create_release.outputs.upload_url }}" | |
RELEASE_ID="${UPLOAD_URL#*releases/}" | |
RELEASE_ID="${RELEASE_ID%%/assets*}" | |
echo "::set-output name=id::$RELEASE_ID" | |
- name: Publish or delete release | |
run: | | |
if ${{ needs.build.result == 'success' }}; then | |
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.get_release_id.outputs.id }} \ | |
-d '{"draft": false}' | |
else | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/v${{ needs.create_release.outputs.new_version }} | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.get_release_id.outputs.id }} | |
fi |