Don't authenticate to registries and comment unused code (#3) #25
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 and release | |
on: | |
push: | |
branches: [trunk] | |
paths-ignore: | |
- 'README.md' | |
- 'setup/action.yml' | |
jobs: | |
build: | |
name: Build | |
runs-on: elvia-runner | |
outputs: | |
version-tag: ${{ steps.get-version.outputs.version_tag }} | |
major-version-tag: ${{ steps.get-version.outputs.major_version_tag }} | |
permissions: | |
contents: read | |
packages: write | |
env: | |
ARTIFACTS_DIR: 'dist' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Resolve version | |
id: get-version | |
run: | | |
version=$(cat VERSION) | |
echo "VERSION_TAG=v$version" >> "$GITHUB_OUTPUT" | |
echo "MAJOR_VERSION_TAG=v$(echo $version | cut -d. -f1)" >> "$GITHUB_OUTPUT" | |
- name: Build, compress and generate checksum | |
run: | | |
binary_name=$(./scripts/build.sh --compress) | |
tarball_name="$binary_name.tar.gz" | |
mkdir -p "$ARTIFACTS_DIR" | |
mv "$tarball_name" "$ARTIFACTS_DIR/" | |
cd "$ARTIFACTS_DIR" | |
md5sum "$tarball_name" > "$tarball_name.md5" | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: '3lv-artifacts' | |
path: ${{ env.ARTIFACTS_DIR }} | |
release: | |
name: Release | |
needs: [build] | |
runs-on: elvia-runner | |
if: ${{ github.event_name == 'push' }} | |
env: | |
VERSION_TAG: ${{ needs.build.outputs.version-tag }} | |
MAJOR_VERSION_TAG: ${{ needs.build.outputs.major-version-tag }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: '3lv-artifacts' | |
- name: Create release if new version | |
run: | | |
latest_version=$(gh release list --json name,isLatest -q '.[] | select(.isLatest == true) | .name') | |
if [[ "$latest_version" == "$VERSION_TAG" ]]; then | |
echo "Version already released." | |
exit 0 | |
fi | |
gh release create "$VERSION_TAG" --generate-notes | |
gh release upload "$VERSION_TAG" ./3lv-linux-amd64.tar.gz | |
gh release upload "$VERSION_TAG" ./3lv-linux-amd64.tar.gz.md5 | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Override old major tag | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git fetch --tags | |
git tag "$MAJOR_VERSION_TAG" "$VERSION_TAG" -f | |
git push --tags -f |