diff --git a/.github/workflows/download.yaml b/.github/workflows/download.yaml index e097bb54c..bc589103f 100644 --- a/.github/workflows/download.yaml +++ b/.github/workflows/download.yaml @@ -3,9 +3,14 @@ on: push: paths: - 'scripts/download-actionlint.bash' + branches: + - '*' + tags-ignore: + - '*' pull_request: paths: - 'scripts/download-actionlint.bash' + workflow_dispatch: jobs: download: @@ -15,8 +20,9 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - name: Download actionlint - run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) + - uses: actions/checkout@v2 + # bash <(curl ...) is not available because it does not download the latest script just after pushing a change + - run: ./scripts/download-actionlint.bash shell: bash id: get_actionlint - name: Run actionlint diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d61c300fa..15fc9aa3a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,6 +9,7 @@ before: builds: - <<: &build_defaults main: ./cmd/actionlint + ldflags: -s -w -X main.version={{.Version}} -X "main.gotFrom=downloaded from release page" env: - CGO_ENABLED=0 id: macos diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b9a3a8d1c..a13508799 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,10 +51,11 @@ make fuzz FUZZ_FUNC=FuzzParse When releasing v1.2.3 as example: -1. Run `./scripts/make-release-tag.bash 1.2.3`. It modifies version string in `cmd/actionlint/main.go`, make a new tag for release, and pushes them to remote -2. Wait until [the CI release job](.github/workflows/release.yaml) completes successfully: +1. Ensure all changes were already pushed to remote by checking `git push origin master` outputs `Everything up-to-date` +2. `git tag v1.2.3 && git push origin v1.2.3` +3. Wait until [the CI release job](.github/workflows/release.yaml) completes successfully: - GoReleaser builds release binaries and make pre-release at GitHub and updates [Homebrew formula](./HomebrewFormula/actionlint.rb) - The CI job also updates version string in `./scripts/download-actionlint.bash` -3. Open the pre-release at [release page](https://github.com/rhysd/actionlint/releases) with browser -4. Write up release notes, uncheck pre-release checkbox and publish the new release -5. Run `git pull && changelog-from-release > CHANGELOG.md` locally to update [CHANGELOG.md](./CHANGELOG.md) +4. Open the pre-release at [release page](https://github.com/rhysd/actionlint/releases) with browser +5. Write up release notes, uncheck pre-release checkbox and publish the new release +6. Run `git pull && changelog-from-release > CHANGELOG.md` locally to update [CHANGELOG.md](./CHANGELOG.md) diff --git a/cmd/actionlint/main.go b/cmd/actionlint/main.go index 6b71ef5c5..2454fc051 100644 --- a/cmd/actionlint/main.go +++ b/cmd/actionlint/main.go @@ -5,12 +5,16 @@ import ( "fmt" "io/ioutil" "os" + "runtime/debug" "github.com/rhysd/actionlint" ) -// This constant is updated by scripts/make-release-tag.bash. Do not modify it manually. -const version = "1.2.0" +// These variables might be modified by ldflags on building release binaries by GoReleaser. Do not modify manually +var ( + version = "" + gotFrom = "built from source" +) const usageHeader = `Usage: actionlint [FLAGS] [FILES...] [-] @@ -49,6 +53,19 @@ func usage() { flag.PrintDefaults() } +func getVersion() string { + if version != "" { + return version + } + + info, ok := debug.ReadBuildInfo() + if !ok { + return "unknown" // Should be unreachable though + } + + return info.Main.Version +} + func run(args []string, opts *actionlint.LinterOptions, initConfig bool) ([]*actionlint.Error, error) { l, err := actionlint.NewLinter(os.Stdout, opts) if err != nil { @@ -100,12 +117,12 @@ func main() { flag.BoolVar(&opts.NoColor, "no-color", false, "Disable colorful output") flag.BoolVar(&opts.Verbose, "verbose", false, "Enable verbose output") flag.BoolVar(&opts.Debug, "debug", false, "Enable debug output (for development)") - flag.BoolVar(&ver, "version", false, "Show version") + flag.BoolVar(&ver, "version", false, "Show version and how this binary was installed") flag.Usage = usage flag.Parse() if ver { - fmt.Println(version) + fmt.Printf("%s\n%s\n", getVersion(), gotFrom) return } diff --git a/scripts/make-release-tag.bash b/scripts/make-release-tag.bash deleted file mode 100755 index 9d2f31800..000000000 --- a/scripts/make-release-tag.bash +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -set -e -o pipefail - -case "$OSTYPE" in - linux-gnu*) sed='sed' ;; - darwin*) sed='gsed' ;; - *) - echo "OS '${OSTYPE}' is not supported. Run this script on Linux or macOS" >&2 - exit 1 - ;; -esac - -if [ ! -d .git ]; then - echo 'Run this script at root of repository' >&2 - exit 1 -fi - -if [[ ! "$1" =~ ^[0-9]+\.[0-9]\.[0-9]$ ]]; then - echo "First argument '$1' does not match to regular expression" '^[0-9]+\.[0-9]\.[0-9]$' >&2 - echo 'Usage: ./scripts/make-release-tag.bash x.y.z' >&2 - exit 1 -fi - -ver="$1" -echo "Update to version $ver" - -set -x -"${sed}" -i -E "s/const version = \"[^\"]+\"/const version = \"$ver\"/" ./cmd/actionlint/main.go -git diff -git add ./cmd/actionlint/main.go -git commit -m "update version to $ver by make-release-tag.bash" -git push -git tag "v${ver}" -git push origin "v${ver}" - -echo "Done successfully"